py.test 2.3.5:使用夹具的生成测试



是否可以将夹具传递给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 夹具功能使用"yield"/上下文管理器集成,起初工作方式与预期不同。

如果要对一系列夹具迭代相同的测试,则可能需要 参数化夹具

最新更新