【发布时间】:2019-06-18 09:45:02
【问题描述】:
我想为我用 pytest 编写的测试创建一个装饰器。我的问题是,调用装饰器时,pytest 会引发装饰器没有参数“test_params”的异常。
装饰器示例:
def decorator_example(fn):
def create(*args, **kwargs):
# any code here
return fn(*args, **kwargs)
return create
测试示例:
@pytest.mark.parametrize(
"test_params",
[
pytest.param("own_parameters")
])
@decorator_example
def test_1(self, fixture1, fixture2, test_params):
pass
并捕获异常:
ValueError: <function create at address> uses no argument 'test_params'
如何创建与 pytest 的参数化测试兼容的装饰器?
【问题讨论】: