我坐下来今天更好地学习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