我正在尝试重复测试 N 次(收集的相同测试)。
原因:通过这样做,我想看看测试速度是否降低了,或者我可以收集一个参数的“平均时间”,然后传递另一个参数并再次获得“平均时间”。
我的理解是使用 def pytest_runteSTLoop()
Hook ,但是我遇到了麻烦。
这是我的钩子(Hook)代码:
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
我做错了什么?有更好的方法吗?
最佳答案
似乎 pytest-2.3.4 在内部保持某种状态,以防止固定装置再次运行。 pytest_runtest_loop
编写时并未考虑您的用例。您可以提交一个关于它的“错误”问题,我们可以看到我们可以做些什么来修复它。 (我快速查看但无法立即看出问题所在,需要更多探索)。
关于python - Py.test 反复循环测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15030010/