【发布时间】:2013-10-10 17:36:39
【问题描述】:
我正在尝试在类 skipif 装饰器中使用 pytest 夹具(范围 = 模块),但我收到一个错误,提示未定义夹具。这可能吗?
conftest.py 有一个名为“target”的模块范围的夹具,它返回一个 CurrentTarget 对象。 CurrentTarget 对象有一个函数 isCommandSupported。 test_mytest.py 有一个包含十几个测试函数的类 Test_MyTestClass。 我想根据fixture target.isCommandSupported 跳过Test_MyTestClass 中的所有测试,所以我用skipif 装饰Test_MyTestClass,如下所示:
@pytest.mark.skipif(not target.isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
我收到此错误:NameError: name 'target' is not defined
如果我尝试:
@pytest.mark.skipif(not pytest.config.getvalue('tgt').isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
我收到此错误:AttributeError: 'function' object has no attribute 'isCommandSupprted'
【问题讨论】:
-
有没有更好的地方问这个问题?
-
我看到 Holger Krekel 在这里回答,但他通常会指向 freenode 聊天以寻求支持问题。 pytest.org/latest/contact.html
-
我偶然发现了同样的issue。您找到问题的解决方案了吗?