shuttle87 shuttle87 - 2 years ago 158
Python Question

limit the maximum running time for unit test

I am currently running some unit tests that might either take a long time before failing or run indefinitely. In a successful test run they will always complete within a certain amount of time. Is it possible to create a pytest unit test that will fail if it does not complete within a certain amount of time?

Answer Source

you can install the pytest-timeout plugin and then mark your test functions with a timeout in seconds.

def test_foo():

Look at the plugin download and usage instructions at

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download