METADATA 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. Metadata-Version: 2.1
  2. Name: pytest-timeout
  3. Version: 1.3.3
  4. Summary: py.test plugin to abort hanging tests
  5. Home-page: http://bitbucket.org/pytest-dev/pytest-timeout/
  6. Author: Floris Bruynooghe
  7. Author-email: flub@devork.be
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Environment :: Console
  12. Classifier: Environment :: Plugins
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: DFSG approved
  15. Classifier: License :: OSI Approved :: MIT License
  16. Classifier: Operating System :: OS Independent
  17. Classifier: Programming Language :: Python
  18. Classifier: Programming Language :: Python :: 2.7
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Topic :: Software Development :: Testing
  21. Requires-Dist: pytest (>=3.6.0)
  22. ==============
  23. pytest-timeout
  24. ==============
  25. This is a plugin which will terminate tests after a certain timeout.
  26. When doing so it will show a stack dump of all threads running at the
  27. time. This is useful when running tests under a continuous
  28. integration server or simply if you don't know why the test suite
  29. hangs.
  30. Note that while by default on POSIX systems py.test will continue to
  31. execute the tests after a test has timed, out this is not always
  32. possible. Often the only sure way to interrupt a hanging test is by
  33. terminating the entire process. As this is a hard termination
  34. (``os._exit()``) it will result in no teardown, JUnit XML output etc.
  35. But the plugin will ensure you will have the debugging output on
  36. stderr nevertheless, which is the most important part at this stage.
  37. See below for detailed information on the timeout methods and their
  38. side-effects.
  39. The pytest-timeout plugin has been tested on python 2.7 or higher,
  40. including 3.X, pypy and pypy3. See tox.ini for currently tested
  41. versions.
  42. Usage
  43. =====
  44. Install is as simple as e.g.::
  45. pip install pytest-timeout
  46. Now you can run tests using a timeout, in seconds, after which they
  47. will be terminated::
  48. py.test --timeout=300
  49. Alternatively you can mark individual tests as having a timeout::
  50. @pytest.mark.timeout(60)
  51. def test_foo():
  52. pass
  53. By default the plugin will not time out any tests, you must specify a
  54. valid timeout for the plugin to interrupt long-running tests. A
  55. timeout is always specified as an integer number of seconds and can be
  56. defined in a number of ways, from low to high priority:
  57. 1. You can set a global timeout in the `py.test configuration file`__
  58. using the ``timeout`` option. E.g.::
  59. [pytest]
  60. timeout = 300
  61. 2. The ``PYTEST_TIMEOUT`` environment variable sets a global timeout
  62. overriding a possible value in the configuration file.
  63. 3. The ``--timeout`` command line option sets a global timeout
  64. overriding both the environment variable and configuration option.
  65. 4. Using the ``timeout`` marker_ on test items you can specify
  66. timeouts on a per-item basis::
  67. @pytest.mark.timeout(300)
  68. def test_foo():
  69. pass
  70. __ http://pytest.org/latest/customize.html#how-test-configuration-is-read-from-configuration-ini-files
  71. .. _marker: http://pytest.org/latest/mark.html
  72. Setting a timeout to 0 seconds disables the timeout, so if you have a
  73. global timeout set you can still disable the timeout by using the
  74. mark.
  75. Timeout Methods
  76. ===============
  77. Interrupting tests which hang is not always as simple and can be
  78. platform dependent. Furthermore some methods of terminating a test
  79. might conflict with the code under test itself. The pytest-timeout
  80. plugin tries to pick the most suitable method based on your platform,
  81. but occasionally you may need to specify a specific timeout method
  82. explicitly.
  83. If a timeout method does not work your safest bet is to use the
  84. *thread* method.
  85. thread
  86. ------
  87. This is the surest and most portable method. It is also the default
  88. on systems not supporting the *signal* method. For each test item the
  89. pytest-timeout plugin starts a timer thread which will terminate the
  90. whole process after the specified timeout. When a test item finishes
  91. this timer thread is cancelled and the test run continues.
  92. The downsides of this method are that there is a relatively large
  93. overhead for running each test and that test runs are not completed.
  94. This means that other py.test features, like e.g. JUnit XML output or
  95. fixture teardown, will not function normally. The second issue might
  96. be alleviated by using the ``--boxed`` option of the pytest-xdist_
  97. plugin.
  98. .. _pytest-xdist: http://pypi.python.org/pypi/pytest-xdist
  99. The benefit of this method is that it will always work. Furthermore
  100. it will still provide you debugging information by printing the stacks
  101. of all the threads in the application to stderr.
  102. signal
  103. ------
  104. If the system supports the SIGALRM signal the *signal* method will be
  105. used by default. This method schedules an alarm when the test item
  106. starts and cancels it when it finishes. If the alarm expires during
  107. the test the signal handler will dump the stack of any other threads
  108. running to stderr and use ``pytest.fail()`` to interrupt the test.
  109. The benefit of this method is that the py.test process is not
  110. terminated and the test run can complete normally.
  111. The main issue to look out for with this method is that it may
  112. interfere with the code under test. If the code under test uses
  113. SIGALRM itself things will go wrong and you will have to choose the
  114. *thread* method.
  115. Specifying the Timeout Method
  116. -----------------------------
  117. The timeout method can be specified by using the ``timeout_method``
  118. option in the `py.test configuration file`__, the ``--timeout_method``
  119. command line parameter or the ``timeout`` marker_. Simply set their
  120. value to the string ``thread`` or ``signal`` to override the default
  121. method. On a marker this is done using the ``method`` keyword::
  122. @pytest.mark.timeout(method='thread')
  123. def test_foo():
  124. pass
  125. __ http://pytest.org/latest/customize.html#how-test-configuration-is-read-from-configuration-ini-files
  126. .. _marker: http://pytest.org/latest/mark.html
  127. The ``timeout`` Marker API
  128. ==========================
  129. The full signature of the timeout marker is::
  130. pytest.mark.timeout(timeout=0, method=DEFAULT_METHOD)
  131. You can use either positional or keyword arguments for both the
  132. timeout and the method. Neither needs to be present.
  133. See the marker api documentation_ and examples_ for the various ways
  134. markers can be applied to test items.
  135. .. _documentation: http://pytest.org/latest/mark.html
  136. .. _examples: http://pytest.org/latest/example/markers.html#marking-whole-classes-or-modules
  137. Timeouts in Fixture Teardown
  138. ============================
  139. The plugin will happily terminate timeouts in the finalisers of
  140. fixtures. The timeout specified applies to the entire process of
  141. setting up fixtures, running the tests and finalising the fixtures.
  142. However when a timeout occurs in a fixture finaliser and the test
  143. suite continues, i.e. the signal method is used, it must be realised
  144. that subsequent fixtures which need to be finalised might not have
  145. been executed, which could result in a broken test-suite anyway. In
  146. case of doubt the thread method which terminates the entire process
  147. might result in clearer output.
  148. Changelog
  149. =========
  150. 1.3.3
  151. -----
  152. - Fix support for pytest >= 3.10.
  153. 1.3.2
  154. -----
  155. - This changelog was ommitted for the 1.3.2 release and was added
  156. afterwards. Apologies for the confusion.
  157. - Fix pytest 3.7.3 compatibility. The capture API had changed
  158. slightly and this needed fixing. Thanks Bruno Oliveira for the
  159. contribution.
  160. 1.3.1
  161. -----
  162. - Fix deprecation warning on Python 3.6. Thanks Mickaël Schoentgen
  163. - Create a valid tag for the release. Somehow this didn't happen for
  164. 1.3.0, that tag points to a non-existing commit.
  165. 1.3.0
  166. -----
  167. - Make it possible to only run the timeout timer on the test function
  168. and not the whole fixture setup + test + teardown duration. Thanks
  169. Pedro Algarvio for the work!
  170. - Use the new pytest marker API, Thanks Pedro Algarvio for the work!
  171. 1.2.1
  172. -----
  173. - Fix for pytest 3.3, thanks Bruno Oliveira.
  174. - Update supported python versions:
  175. - Add CPython 3.6.
  176. - Drop CPyhon 2.6 (as did pytest 3.3)
  177. - Drop CPyhon 3.3
  178. - Drop CPyhon 3.4
  179. 1.2.0
  180. -----
  181. * Allow using floats as timeout instead of only integers, thanks Tom
  182. Myers.
  183. 1.1.0
  184. -----
  185. * Report (default) timeout duration in header, thanks Holger Krekel.
  186. 1.0.0
  187. -----
  188. * Bump version to 1.0 to commit to semantic versioning.
  189. * Fix issue #12: Now compatible with py.test 2.8, thanks Holger Krekel.
  190. * No longer test with pexpect on py26 as it is no longer supported
  191. * Require py.test 2.8 and use new hookimpl decorator
  192. 0.5
  193. ---
  194. * Timeouts will no longer be triggered when inside an interactive pdb
  195. session started by ``pytest.set_trace()`` / ``pdb.set_trace()``.
  196. * Add pypy3 environment to tox.ini.
  197. * Transfer repository to pytest-dev team account.
  198. 0.4
  199. ---
  200. * Support timeouts happening in (session scoped) finalizers.
  201. * Change command line option --timeout_method into --timeout-method
  202. for consistency with py.test
  203. 0.3
  204. ---
  205. * Added the PYTEST_TIMEOUT environment variable as a way of specifying
  206. the timeout (closes issue #2).
  207. * More flexible marker argument parsing: you can now specify the
  208. method using a positional argument.
  209. * The plugin is now enabled by default. There is no longer a need to
  210. specify ``timeout=0`` in the configuration file or on the command
  211. line simply so that a marker would work.
  212. 0.2
  213. ---
  214. * Add a marker to modify the timeout delay using a @pytest.timeout(N)
  215. syntax, thanks to Laurant Brack for the initial code.
  216. * Allow the timeout marker to select the timeout method using the
  217. ``method`` keyword argument.
  218. * Rename the --nosigalrm option to --method=thread to future proof
  219. support for eventlet and gevent. Thanks to Ronny Pfannschmidt for
  220. the hint.
  221. * Add ``timeout`` and ``timeout_method`` items to the configuration
  222. file so you can enable and configure the plugin using the ini file.
  223. Thanks to Holger Krekel and Ronny Pfannschmidt for the hints.
  224. * Tested (and fixed) for python 2.6, 2.7 and 3.2.