Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout for all the test cases in pytest

Tags:

pytest

I have the requirement to stop test cases with overall timeout, not at test case level. so if lets say i have 300 test cases I want to timeout with overall time as 300 seconds.

Is there a way to do that? Sample command used to run pytest pytest.py --junitxml=artifacts/junitresults.xml -s --gatherlogs=true --durations=2000 tests/spark

like image 977
Vivek Pemawat Avatar asked Mar 16 '17 08:03

Vivek Pemawat


People also ask

Does pytest have a timeout?

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.

How can I make pytest run faster?

Using the norecursedirs option in pytest. ini or tox. ini can save a lot of collection time, depending on what other files you have in your working directory. My collection time is roughly halved for a suite of 300 tests when I have that in place (0.34s vs 0.64s).

How do I skip Testcases in pytest?

The simplest way to skip a test is to mark it with the skip decorator which may be passed an optional reason . It is also possible to skip imperatively during test execution or setup by calling the pytest. skip(reason) function. This is useful when it is not possible to evaluate the skip condition during import time.


1 Answers

take a look at this pytest plugin: https://pypi.python.org/pypi/pytest-timeout it most probably suits your use case.

You can set a global timeout in a number of ways, the most simple one being the --timeout command line option that "sets a global timeout overriding both the environment variable and configuration option" after which the tests will be terminated:

py.test --timeout=300
like image 145
Enrique Saez Avatar answered Jan 02 '23 23:01

Enrique Saez