pytest 中测试之间的间隔

Pit*_*kos 5 sleep intervals pytest

在 pytest 中是否有在测试之间添加间隔的常见做法?目前集成测试失败,但如果单独运行测试则可以正常工作。

小智 18

您可以在 pytest 中使用自动使用装置在测试用例之间自动休眠:

@pytest.fixture(autouse=True)
def slow_down_tests():
    yield
    time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

该夹具将自动用于所有测试用例,并将执行测试用例,以便它可以正常运行,但当测试完成时,执行将返回到该夹具,并且将运行睡眠。