3

テストを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?

4

1 に答える 1

2

pytest-2.3.4 は、フィクスチャが再び実行されないようにする状態を内部的に保持しているようです。 pytest_runtest_loopあなたのユースケースを念頭に置いて書かれていませんでした。それについて「バグ」問題を提出することができます。それを修正するために何ができるかを確認できます。(すぐに調べましたが、何が問題なのかすぐにはわかりませんでした。さらに調査する必要があります)。

于 2013-02-26T11:31:07.430 に答える