gpt4 book ai didi

python - py.test 2.3.5 : generative tests that use fixtures?

转载 作者:行者123 更新时间:2023-11-28 20:24:02 25 4
gpt4 key购买 nike

是否可以将 fixture 传递给 pytest 生成测试?

import py.test

@py.test.fixture(scope="module")
def fixture():
return True

def test_1(fixture):
def checker(datum):
assert datum == fixture
for i in [True, True, True]:
# Does not work.
yield checker, i
# Does work.
#checker(i)

以上代码产生

>       for i, x in enumerate(self.obj()):
name, call, args = self.getcallargs(x)
E TypeError: test_1() takes exactly 1 argument (0 given)

我们使用 Debian 的 py.test 2.3.5。

最佳答案

不确切知道测试定义中的 yield 应该做什么。

灯具中有 yield Fixture functions using “yield” / context manager integration一开始并不像预期的那样工作。

如果你想在你可能需要 Parametrizing a fixture 的固定装置序列上迭代相同的测试

关于python - py.test 2.3.5 : generative tests that use fixtures?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com