pytest-timeout

Software Screenshot:
pytest-timeout
Software Details:
Version: 0.3
Upload Date: 20 Feb 15
Developer: Floris Bruynooghe
Distribution Type: Freeware
Downloads: 136

Rating: 5.0/5 (Total Votes: 1)

pytest-timeout is a plugin for py.test which will terminate tests after a certain timeout. When doing so you will get a stack dump of all threads running at the time. This is useful when e.g. running tests under a continuous integration (CI) server.

Usage

Install via:

pip install pytest-timeout

and then enable the plugin, either from the command line:

py.test -p timeout

or more conveniently from within the test module or conftest.py:

pytest_plugins = 'timeout'

You can change the timeout using the --timeout parameter which sets the timeout in seconds.

How It Works

This plugin works in one of two ways. If the system supports the SIGALRM signal an alarm will be scheduled when the tests starts and cancelled when it finishes. If the alarm expires during the test the signal handler will use pytest.fail() to interrupt the test after having dumped the stack of any other threads running to stderr.

If the system does not support SIGALRM or the --nosigalrm option was used then a timer thread will be used instead. Once more, if this timer is not cancelled before it expires it will dump the stack of all threads to stderr before terminating the entire py.test process using os._exit(1).

The downside of the SIGALRM method is that the signal is used by the test framework. If this signal is used by the code under test you will need to use the --nosigalrm option. The limitation of the timer thread however is the extra overhead of creating a thread for each executed test and the fact that after one timeout the entire process is stopped and no further tests are executed.

What is new in this release:

  • Added the PYTEST_TIMEOUT environment variable as a way of specifying the timeout (closes issue #2).
  • More flexible marker argument parsing: you can now specify the method using a positional argument.
  • The plugin is now enabled by default. There is no longer a need to specify timeout=0 in the configuration file or on the command line simply so that a marker would work.

What is new in version 0.2:

  • Add a marker to modify the timeout delay using a @pytest.timeout(N) syntax, thanks to Laurant Brack for the initial code.
  • Allow the timeout marker to select the timeout method using the method keyword argument.
  • Rename the --nosigalrm option to --method=thread to future proof support for eventlet and gevent. Thanks to Ronny Pfannschmidt for the hint.
  • Add timeout and timeout_method items to the configuration file so you can enable and configure the plugin using the ini file. Thanks to Holger Krekel and Ronny Pfannschmidt for the hints.
  • Tested (and fixed) for python 2.6, 2.7 and 3.2.

Requirements:

  • Python
  • py.test

Similar Software

Sipbomber
Sipbomber

3 Jun 15

LAMPcheck
LAMPcheck

2 Jun 15

nbdebug
nbdebug

11 May 15

Comments to pytest-timeout

Comments not found
Add Comment
Turn on images!