我坐下來今天更好地學習py.test,發現網站的文檔已關閉(pytest.org),所以我很抱歉如果在這裏找到了這個問題的答案。pytest中參數的輸出
我想要做的是兩場比賽的輸出傳遞到參數多態,像這樣:
import pytest
@pytest.fixture()
def make_1():
return 1
@pytest.fixture()
def make_2():
return 2
@pytest.mark.parametrize('arg', [make_1, make_2])
def test_main(arg):
assert isinstance(arg, int)
但測試失敗,因爲,而不是分配燈具參數「ARG」的輸出燈具(功能)本身被傳遞。
如何以這種方式參數化各種燈具的輸出?
是否有一個原因,你不能讓'make_1'成爲一個普通的函數 - 它需要是一個燈具,因爲它使用其他燈具或什麼? –
在參數化中不能使用fixtue。 https://bitbucket.org/pytest-dev/pytest/issues/349/using-fixtures-in-pytestmarkparametrize –
這也是一個非常有用的解決方法:https://github.com/pytest-dev/pytest/issues/ 349#issuecomment-189370273 – derchambers