Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interval between tests in pytest

Is there a common practice to add interval between tests in pytest? Currently integration tests fail but work fine if running the tests individually.

like image 420
Pithikos Avatar asked Jul 09 '26 23:07

Pithikos


1 Answers

You can use autouse fixtures in pytest to automatically sleep in between test cases:

@pytest.fixture(autouse=True)
def slow_down_tests():
    yield
    time.sleep(1)

This fixture will automatically be used for all test cases and will yield execution to a test case so it can run normally, but when the test finishes, the execution will come back to this fixture and the sleep will be run.

like image 81
Jad Chaar Avatar answered Jul 13 '26 12:07

Jad Chaar