如何使py.test忽略decorator中的测试参数?

时间:2017-11-30 14:18:17

标签: python testing mocking decorator pytest

我试图为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
...

0 个答案:

没有答案