Py.test循环执行测试

3
我将尝试重复收集的测试N次。
原因:我想看看测试速度是否会降低,或者我能否收集一个参数的“平均时间”,然后传递另一个参数并再次获取“平均时间”。
我的理解是使用def pytest_runtestloop()钩子,但是我遇到了困难。
以下是我的钩子代码:
def pytest_runtestloop(session):
    repeat = int(session.config.option.repeat)
    assert isinstance(repeat, int), "Repeat must be an integer"
    for i in range(repeat): #@UnusedVariable                      
        session.config.pluginmanager.getplugin("main").pytest_runtestloop(session)

    return True

问题在于“设置”仅在第一次运行时运行: 例如:
class TestSomething(object):

    @classmethod
    @pytest.fixture(scope = "class", autouse = True)
    def setup(self):
        //setup function

    def test_something(self):
        //test function

这里setup只会在第一次循环时调用,而如果设置了session.config.option.repeat为2,则test_something将被调用两次。

我做错了什么?有更好的方法吗?

1个回答

2

看起来pytest-2.3.4会在内部保留一些状态,防止夹具再次运行。 pytest_runtest_loop 不是为您的用例编写的。 您可以提交一个“错误”问题,然后我们可以看看如何修复它。(我快速查看了一下,但无法立即看出问题所在,需要更多的探索)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接