我将尝试重复收集的测试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
将被调用两次。
我做错了什么?有更好的方法吗?