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?
Still, it seems as though a 10 second short-term attention span is more or less hard-wired into the human brain. Thus, a unit test suite used for TDD should run in less than 10 seconds. If it's slower, you'll be less productive because you'll constantly lose focus.
All unit tests should run in under a second (that is all unit tests combined should run in 1 second).
For each test item the pytest-timeout plugin starts a timer thread which will terminate the whole process after the specified timeout. When a test item finishes this timer thread is cancelled and the test run continues.
To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).
you can install the pytest-timeout plugin and then mark your test functions with a timeout in seconds.
@pytest.mark.timeout(300) def test_foo(): pass
Look at the plugin download and usage instructions at https://pypi.python.org/pypi/pytest-timeout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With