我想在一個類的skipif裝飾器中使用pytest fixture(scope = module),但是我收到一個錯誤,提示燈具沒有定義。這可能嗎?我可以在我的skipif邏輯條件下使用pytest夾具嗎?
conftest.py有一個模塊作用域稱爲'目標',返回一個CurrentTarget對象的夾具。 CurrentTarget對象具有isCommandSupported函數。 test_mytest.py有一個Test_MyTestClass類,它包含一打測試函數。 我想跳過所有Test_MyTestClass根據測試,如果燈具target.isCommandSupported所以我裝飾Test_MyTestClass與SKIPIF像:
@pytest.mark.skipif(not target.isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
我得到這個錯誤:NameError:名字「目標」沒有定義
如果我嘗試:
@pytest.mark.skipif(not pytest.config.getvalue('tgt').isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
我得到這個錯誤:AttributeError的: '功能' 對象有沒有屬性 'isCommandSupprted'
有沒有更好的地方要問這個問題? –
我在這裏看到Holger Krekel的答案,但他通常指向freenode聊天支持問題。 http://pytest.org/latest/contact.html – Anthon
我偶然發現了相同的[問題](http://stackoverflow.com/questions/28179026/how-to-skip-a-pytest-using-an-external -fixture)。你有沒有找到解決這個問題的辦法? –