【发布时间】:2017-09-01 15:43:25
【问题描述】:
我在我的 pytest 单元测试中使用固定装置时遇到了困难。
我正在使用这样的测试类:
class TestMyApp(object):
def setup(self):
self.client = mock_client()
@pytest.fixture
def client_item(self):
return self.client.create_item('test_item')
def test_something1(self, client_item):
# Test here.
pass
当我运行上述测试时,我得到以下异常:
AttributeError: 'TestMyApp' object has no attribute 'client'
我相信这是因为 client_item() 固定函数在 setup() 函数之前被调用。
我是否错误地使用了固定装置?或者有什么方法可以强制在夹具功能之前调用setup()?
提前致谢。
【问题讨论】:
标签: python python-3.x unit-testing pytest