テストをN回繰り返しようとしています(収集された同じテスト)。
理由: 実行することで、テストの速度が低下するかどうか、または 1 つのパラメーターの「平均時間」を収集してから他のパラメーターを渡して「平均時間」を再度取得できるかどうかを確認します。
私の理解では、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
The problem is that it the "setups" are run only the first time: For example:
class TestSomething(object):
@classmethod
@pytest.fixture(scope = "class", autouse = True)
def setup(self):
//setup function
def test_something(self):
//test function
Here setup
will be called during the first cycle only, and test_something
would be called both times if I set session.config.option.repeat
to 2
What am I doing wrong? Is there better approach?