小编Chi*_*son的帖子

我可以在我的 skipif 逻辑的条件下使用 pytest 固定装置吗?

我正在尝试在类 skipif 装饰器中使用 pytest 固定装置(范围=模块),但是我收到一条错误消息,指出未定义固定装置。这可能吗?

conftest.py 有一个名为“target”的模块范围的夹具,它返回一个 CurrentTarget 对象。CurrentTarget 对象有一个函数 isCommandSupported。test_mytest.py 有一个包含十几个测试函数的类 Test_MyTestClass。我想根据夹具 target.isCommandSupported 跳过 Test_MyTestClass 中的所有测试,所以我用 skipif 装饰 Test_MyTestClass ,例如:

@pytest.mark.skipif(not target.isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
Run Code Online (Sandbox Code Playgroud)

我收到此错误: NameError: name 'target' is not defined

如果我尝试:

@pytest.mark.skipif(not pytest.config.getvalue('tgt').isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
Run Code Online (Sandbox Code Playgroud)

我收到此错误: AttributeError: 'function' object has no attribute 'isCommandSupprted'

fixture pytest

6
推荐指数
2
解决办法
4161
查看次数

标签 统计

fixture ×1

pytest ×1