我试图为py.test创建自定义模拟类。我想在test中发送mock_data,作为第一个参数。但py.test将其识别为夹具名称,并引发异常。如果使用删除decorator.decorator
,它会在参数中丢失固定装置。
from decorator import decorator
class mocker(object):
...
def __call__(self, func):
def patched(*args, **kwargs):
self.setup_mocks()
return func(self.mock_data, *args, **kwrgs)
return decorator(patched, func)
...
@mocker
def test_some_func(mock_data, some_fixture):
pass
提升它:
def (mock_data, some_fixture):
E fixture 'mock_data' not found
...