pytest-timeout


Namepytest-timeout JSON
Version 2.2.0 PyPI version JSON
download
home_pagehttps://github.com/pytest-dev/pytest-timeout
Summarypytest plugin to abort hanging tests
upload_time2023-10-08 10:14:25
maintainer
docs_urlNone
authorFloris Bruynooghe
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ==============
pytest-timeout
==============

|python| |version| |anaconda| |ci| |pre-commit|

.. |version| image:: https://img.shields.io/pypi/v/pytest-timeout.svg
  :target: https://pypi.python.org/pypi/pytest-timeout

.. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-timeout.svg
  :target: https://anaconda.org/conda-forge/pytest-timeout

.. |ci| image:: https://github.com/pytest-dev/pytest-timeout/workflows/build/badge.svg
  :target: https://github.com/pytest-dev/pytest-timeout/actions

.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-timeout.svg
  :target: https://pypi.python.org/pypi/pytest-timeout/

.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest-timeout/master.svg
   :target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest-timeout/master


.. warning::

   Please read this README carefully and only use this plugin if you
   understand the consequences.  This plugin is designed to catch
   excessively long test durations like deadlocked or hanging tests,
   it is not designed for precise timings or performance regressions.
   Remember your test suite should aim to be **fast**, with timeouts
   being a last resort, not an expected failure mode.

This plugin will time each test and terminate it when it takes too
long.  Termination may or may not be graceful, please see below, but
when aborting it will show a stack dump of all thread running at the
time.  This is useful when running tests under a continuous
integration server or simply if you don't know why the test suite
hangs.

.. note::

   While by default on POSIX systems pytest will continue to execute
   the tests after a test has timed out this is not always possible.
   Often the only sure way to interrupt a hanging test is by
   terminating the entire process.  As this is a hard termination
   (``os._exit()``) it will result in no teardown, JUnit XML output
   etc.  But the plugin will ensure you will have the debugging output
   on stderr nevertheless, which is the most important part at this
   stage.  See below for detailed information on the timeout methods
   and their side-effects.

The pytest-timeout plugin has been tested on Python 3.6 and higher,
including PyPy3.  See tox.ini for currently tested versions.


Usage
=====

Install is as simple as e.g.::

   pip install pytest-timeout

Now you can run the test suite while setting a timeout in seconds, any
individual test which takes longer than the given duration will be
terminated::

   pytest --timeout=300

Furthermore you can also use a decorator to set the timeout for an
individual test.  If combined with the ``--timeout`` flag this will
override the timeout for this individual test:

.. code:: python

   @pytest.mark.timeout(60)
   def test_foo():
       pass

By default the plugin will not time out any tests, you must specify a
valid timeout for the plugin to interrupt long-running tests.  A
timeout is always specified as a number of seconds, and can be
defined in a number of ways, from low to high priority:

1. You can set a global timeout in the `pytest configuration file`__
   using the ``timeout`` option.  E.g.:

   .. code:: ini

      [pytest]
      timeout = 300

2. The ``PYTEST_TIMEOUT`` environment variable sets a global timeout
   overriding a possible value in the configuration file.

3. The ``--timeout`` command line option sets a global timeout
   overriding both the environment variable and configuration option.

4. Using the ``timeout`` marker_ on test items you can specify
   timeouts on a per-item basis:

   .. code:: python

      @pytest.mark.timeout(300)
      def test_foo():
          pass

__ https://docs.pytest.org/en/latest/reference.html#ini-options-ref

.. _marker: https://docs.pytest.org/en/latest/mark.html

Setting a timeout to 0 seconds disables the timeout, so if you have a
global timeout set you can still disable the timeout by using the
mark.

Timeout Methods
===============

Interrupting tests which hang is not always as simple and can be
platform dependent.  Furthermore some methods of terminating a test
might conflict with the code under test itself.  The pytest-timeout
plugin tries to pick the most suitable method based on your platform,
but occasionally you may need to specify a specific timeout method
explicitly.

   If a timeout method does not work your safest bet is to use the
   *thread* method.

thread
------

This is the surest and most portable method.  It is also the default
on systems not supporting the *signal* method.  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.

The downsides of this method are that there is a relatively large
overhead for running each test and that test runs are not completed.
This means that other pytest features, like e.g. JUnit XML output or
fixture teardown, will not function normally.  The second issue might
be alleviated by using the ``--boxed`` option of the pytest-xdist_
plugin.

.. _pytest-xdist: https://pypi.org/project/pytest-xdist/

The benefit of this method is that it will always work.  Furthermore
it will still provide you debugging information by printing the stacks
of all the threads in the application to stderr.

signal
------

If the system supports the SIGALRM signal the *signal* method will be
used by default.  This method schedules an alarm when the test item
starts and cancels the alarm when the test finishes.  If the alarm expires
during the test the signal handler will dump the stack of any other threads
running to stderr and use ``pytest.fail()`` to interrupt the test.

The benefit of this method is that the pytest process is not
terminated and the test run can complete normally.

The main issue to look out for with this method is that it may
interfere with the code under test.  If the code under test uses
SIGALRM itself things will go wrong and you will have to choose the
*thread* method.

Specifying the Timeout Method
-----------------------------

The timeout method can be specified by using the ``timeout_method``
option in the `pytest configuration file`__, the ``--timeout_method``
command line parameter or the ``timeout`` marker_.  Simply set their
value to the string ``thread`` or ``signal`` to override the default
method.  On a marker this is done using the ``method`` keyword:

.. code:: python

   @pytest.mark.timeout(method="thread")
   def test_foo():
       pass

__ https://docs.pytest.org/en/latest/reference.html#ini-options-ref

.. _marker: https://docs.pytest.org/en/latest/mark.html

The ``timeout`` Marker API
==========================

The full signature of the timeout marker is:

.. code:: python

   pytest.mark.timeout(timeout=0, method=DEFAULT_METHOD)

You can use either positional or keyword arguments for both the
timeout and the method.  Neither needs to be present.

See the marker api documentation_ and examples_ for the various ways
markers can be applied to test items.

.. _documentation: https://docs.pytest.org/en/latest/mark.html

.. _examples: https://docs.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules


Timeouts in Fixture Teardown
============================

The plugin will happily terminate timeouts in the finalisers of
fixtures.  The timeout specified applies to the entire process of
setting up fixtures, running the tests and finalising the fixtures.
However when a timeout occurs in a fixture finaliser and the test
suite continues, i.e. the signal method is used, it must be realised
that subsequent fixtures which need to be finalised might not have
been executed, which could result in a broken test-suite anyway.  In
case of doubt the thread method which terminates the entire process
might result in clearer output.

Avoiding timeouts in Fixtures
=============================

The timeout applies to the entire test including any fixtures which
may need to be setup or torn down for the test (the exact affected
fixtures depends on which scope they are and whether other tests will
still use the same fixture).  If the timeouts really are too short to
include fixture durations, firstly make the timeouts larger ;).  If
this really isn't an option a ``timeout_func_only`` boolean setting
exists which can be set in the pytest ini configuration file, as
documented in ``pytest --help``.


Debugger Detection
==================

This plugin tries to avoid triggering the timeout when a debugger is
detected.  This is mostly a convenience so you do not need to remember
to disable the timeout when interactively debugging.

The way this plugin detects whether or not a debugging session is
active is by checking if a trace function is set and if one is, it
check to see if the module it belongs to is present in a set of known
debugging frameworks modules OR if pytest itself drops you into a pdb
session using ``--pdb`` or similar.

This functionality can be disabled with the ``--disable-debugger-detection`` flag
or the corresponding ``timeout_disable_debugger_detection`` ini setting / environment
variable.


Extending pytest-timeout with plugins
=====================================

``pytest-timeout`` provides two hooks that can be used for extending the tool.  These
hooks are used for setting the timeout timer and cancelling it if the timeout is not
reached.

For example, ``pytest-asyncio`` can provide asyncio-specific code that generates better
traceback and points on timed out ``await`` instead of the running loop iteration.

See `pytest hooks documentation
<https://docs.pytest.org/en/latest/how-to/writing_hook_functions.html>`_ for more info
regarding to use custom hooks.

``pytest_timeout_set_timer``
----------------------------

.. code:: python

   @pytest.hookspec(firstresult=True)
   def pytest_timeout_set_timer(item, settings):
       """Called at timeout setup.

       'item' is a pytest node to setup timeout for.

       'settings' is Settings namedtuple (described below).

       Can be overridden by plugins for alternative timeout implementation strategies.
       """


``Settings``
------------

When ``pytest_timeout_set_timer`` is called, ``settings`` argument is passed.

The argument has ``Settings`` namedtuple type with the following fields:

+-----------+-------+--------------------------------------------------------+
|Attribute  | Index | Value                                                  |
+===========+=======+========================================================+
| timeout   | 0     | timeout in seconds or ``None`` for no timeout          |
+-----------+-------+--------------------------------------------------------+
| method    | 1     | Method mechanism,                                      |
|           |       | ``'signal'`` and ``'thread'`` are supported by default |
+-----------+-------+--------------------------------------------------------+
| func_only | 2     | Apply timeout to test function only if ``True``,       |
|           |       |  wrap all test function and its fixtures otherwise     |
+-----------+-------+--------------------------------------------------------+

``pytest_timeout_cancel_timer``
-------------------------------

.. code:: python

   @pytest.hookspec(firstresult=True)
   def pytest_timeout_cancel_timer(item):
       """Called at timeout teardown.

       'item' is a pytest node which was used for timeout setup.

       Can be overridden by plugins for alternative timeout implementation strategies.
       """

``is_debugging``
----------------

When the timeout occurs, user can open the debugger session. In this case, the timeout
should be discarded.  A custom hook can check this case by calling ``is_debugging()``
function:

.. code:: python

   import pytest
   import pytest_timeout


   def on_timeout():
       if pytest_timeout.is_debugging():
           return
       pytest.fail("+++ Timeout +++")


Changelog
=========

2.2.0
-----

- Add ``--timeout-disable-debugger-detection`` flag, thanks
  Michael Peters

2.1.0
-----

- Get terminal width from shutil instead of deprecated py, thanks
  Andrew Svetlov.
- Add an API for extending ``pytest-timeout`` functionality
  with third-party plugins, thanks Andrew Svetlov.

2.0.2
-----

- Fix debugger detection on OSX, thanks Alexander Pacha.

2.0.1
-----

- Fix Python 2 removal, thanks Nicusor Picatureanu.

2.0.0
-----

- Increase pytest requirement to >=5.0.0.  Thanks Dominic Davis-Foster.
- Use thread timeout method when plugin is not called from main
  thread to avoid crash.
- Fix pycharm debugger detection so timeouts are not triggered during
  debugger usage.
- Dropped support for Python 2, minimum pytest version supported is 5.0.0.

1.4.2
-----

- Fix compatibility when run with pytest pre-releases, thanks
  Bruno Oliveira,
- Fix detection of third-party debuggers, thanks Bruno Oliveira.

1.4.1
-----

- Fix coverage compatibility which was broken by 1.4.0.

1.4.0
-----

- Better detection of when we are debugging, thanks Mattwmaster58.

1.3.4
-----

- Give the threads a name to help debugging, thanks Thomas Grainger.
- Changed location to https://github.com/pytest-dev/pytest-timeout
  because bitbucket is dropping mercurial support.  Thanks Thomas
  Grainger and Bruno Oliveira.

1.3.3
-----

- Fix support for pytest >= 3.10.

1.3.2
-----

- This changelog was omitted for the 1.3.2 release and was added
  afterwards.  Apologies for the confusion.
- Fix pytest 3.7.3 compatibility.  The capture API had changed
  slightly and this needed fixing.  Thanks Bruno Oliveira for the
  contribution.

1.3.1
-----

- Fix deprecation warning on Python 3.6.  Thanks Mickaƫl Schoentgen
- Create a valid tag for the release.  Somehow this didn't happen for
  1.3.0, that tag points to a non-existing commit.

1.3.0
-----

- Make it possible to only run the timeout timer on the test function
  and not the whole fixture setup + test + teardown duration.  Thanks
  Pedro Algarvio for the work!
- Use the new pytest marker API, Thanks Pedro Algarvio for the work!

1.2.1
-----

- Fix for pytest 3.3, thanks Bruno Oliveira.
- Update supported python versions:
  - Add CPython 3.6.
  - Drop CPyhon 2.6 (as did pytest 3.3)
  - Drop CPyhon 3.3
  - Drop CPyhon 3.4

1.2.0
-----

* Allow using floats as timeout instead of only integers, thanks Tom
  Myers.

1.1.0
-----

* Report (default) timeout duration in header, thanks Holger Krekel.

1.0.0
-----

* Bump version to 1.0 to commit to semantic versioning.
* Fix issue #12: Now compatible with pytest 2.8, thanks Holger Krekel.
* No longer test with pexpect on py26 as it is no longer supported
* Require pytest 2.8 and use new hookimpl decorator

0.5
---

* Timeouts will no longer be triggered when inside an interactive pdb
  session started by ``pytest.set_trace()`` / ``pdb.set_trace()``.

* Add pypy3 environment to tox.ini.

* Transfer repository to pytest-dev team account.

0.4
---

* Support timeouts happening in (session scoped) finalizers.

* Change command line option --timeout_method into --timeout-method
  for consistency with pytest

0.3
---

* 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.


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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pytest-dev/pytest-timeout",
    "name": "pytest-timeout",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Floris Bruynooghe",
    "author_email": "flub@devork.be",
    "download_url": "https://files.pythonhosted.org/packages/2a/b0/8e3182e9ed65ad5b247f9d13769f214fc52b0d3522c3e1c8dbfa2f879e5a/pytest-timeout-2.2.0.tar.gz",
    "platform": null,
    "description": "==============\npytest-timeout\n==============\n\n|python| |version| |anaconda| |ci| |pre-commit|\n\n.. |version| image:: https://img.shields.io/pypi/v/pytest-timeout.svg\n  :target: https://pypi.python.org/pypi/pytest-timeout\n\n.. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-timeout.svg\n  :target: https://anaconda.org/conda-forge/pytest-timeout\n\n.. |ci| image:: https://github.com/pytest-dev/pytest-timeout/workflows/build/badge.svg\n  :target: https://github.com/pytest-dev/pytest-timeout/actions\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-timeout.svg\n  :target: https://pypi.python.org/pypi/pytest-timeout/\n\n.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest-timeout/master.svg\n   :target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest-timeout/master\n\n\n.. warning::\n\n   Please read this README carefully and only use this plugin if you\n   understand the consequences.  This plugin is designed to catch\n   excessively long test durations like deadlocked or hanging tests,\n   it is not designed for precise timings or performance regressions.\n   Remember your test suite should aim to be **fast**, with timeouts\n   being a last resort, not an expected failure mode.\n\nThis plugin will time each test and terminate it when it takes too\nlong.  Termination may or may not be graceful, please see below, but\nwhen aborting it will show a stack dump of all thread running at the\ntime.  This is useful when running tests under a continuous\nintegration server or simply if you don't know why the test suite\nhangs.\n\n.. note::\n\n   While by default on POSIX systems pytest will continue to execute\n   the tests after a test has timed out this is not always possible.\n   Often the only sure way to interrupt a hanging test is by\n   terminating the entire process.  As this is a hard termination\n   (``os._exit()``) it will result in no teardown, JUnit XML output\n   etc.  But the plugin will ensure you will have the debugging output\n   on stderr nevertheless, which is the most important part at this\n   stage.  See below for detailed information on the timeout methods\n   and their side-effects.\n\nThe pytest-timeout plugin has been tested on Python 3.6 and higher,\nincluding PyPy3.  See tox.ini for currently tested versions.\n\n\nUsage\n=====\n\nInstall is as simple as e.g.::\n\n   pip install pytest-timeout\n\nNow you can run the test suite while setting a timeout in seconds, any\nindividual test which takes longer than the given duration will be\nterminated::\n\n   pytest --timeout=300\n\nFurthermore you can also use a decorator to set the timeout for an\nindividual test.  If combined with the ``--timeout`` flag this will\noverride the timeout for this individual test:\n\n.. code:: python\n\n   @pytest.mark.timeout(60)\n   def test_foo():\n       pass\n\nBy default the plugin will not time out any tests, you must specify a\nvalid timeout for the plugin to interrupt long-running tests.  A\ntimeout is always specified as a number of seconds, and can be\ndefined in a number of ways, from low to high priority:\n\n1. You can set a global timeout in the `pytest configuration file`__\n   using the ``timeout`` option.  E.g.:\n\n   .. code:: ini\n\n      [pytest]\n      timeout = 300\n\n2. The ``PYTEST_TIMEOUT`` environment variable sets a global timeout\n   overriding a possible value in the configuration file.\n\n3. The ``--timeout`` command line option sets a global timeout\n   overriding both the environment variable and configuration option.\n\n4. Using the ``timeout`` marker_ on test items you can specify\n   timeouts on a per-item basis:\n\n   .. code:: python\n\n      @pytest.mark.timeout(300)\n      def test_foo():\n          pass\n\n__ https://docs.pytest.org/en/latest/reference.html#ini-options-ref\n\n.. _marker: https://docs.pytest.org/en/latest/mark.html\n\nSetting a timeout to 0 seconds disables the timeout, so if you have a\nglobal timeout set you can still disable the timeout by using the\nmark.\n\nTimeout Methods\n===============\n\nInterrupting tests which hang is not always as simple and can be\nplatform dependent.  Furthermore some methods of terminating a test\nmight conflict with the code under test itself.  The pytest-timeout\nplugin tries to pick the most suitable method based on your platform,\nbut occasionally you may need to specify a specific timeout method\nexplicitly.\n\n   If a timeout method does not work your safest bet is to use the\n   *thread* method.\n\nthread\n------\n\nThis is the surest and most portable method.  It is also the default\non systems not supporting the *signal* method.  For each test item the\npytest-timeout plugin starts a timer thread which will terminate the\nwhole process after the specified timeout.  When a test item finishes\nthis timer thread is cancelled and the test run continues.\n\nThe downsides of this method are that there is a relatively large\noverhead for running each test and that test runs are not completed.\nThis means that other pytest features, like e.g. JUnit XML output or\nfixture teardown, will not function normally.  The second issue might\nbe alleviated by using the ``--boxed`` option of the pytest-xdist_\nplugin.\n\n.. _pytest-xdist: https://pypi.org/project/pytest-xdist/\n\nThe benefit of this method is that it will always work.  Furthermore\nit will still provide you debugging information by printing the stacks\nof all the threads in the application to stderr.\n\nsignal\n------\n\nIf the system supports the SIGALRM signal the *signal* method will be\nused by default.  This method schedules an alarm when the test item\nstarts and cancels the alarm when the test finishes.  If the alarm expires\nduring the test the signal handler will dump the stack of any other threads\nrunning to stderr and use ``pytest.fail()`` to interrupt the test.\n\nThe benefit of this method is that the pytest process is not\nterminated and the test run can complete normally.\n\nThe main issue to look out for with this method is that it may\ninterfere with the code under test.  If the code under test uses\nSIGALRM itself things will go wrong and you will have to choose the\n*thread* method.\n\nSpecifying the Timeout Method\n-----------------------------\n\nThe timeout method can be specified by using the ``timeout_method``\noption in the `pytest configuration file`__, the ``--timeout_method``\ncommand line parameter or the ``timeout`` marker_.  Simply set their\nvalue to the string ``thread`` or ``signal`` to override the default\nmethod.  On a marker this is done using the ``method`` keyword:\n\n.. code:: python\n\n   @pytest.mark.timeout(method=\"thread\")\n   def test_foo():\n       pass\n\n__ https://docs.pytest.org/en/latest/reference.html#ini-options-ref\n\n.. _marker: https://docs.pytest.org/en/latest/mark.html\n\nThe ``timeout`` Marker API\n==========================\n\nThe full signature of the timeout marker is:\n\n.. code:: python\n\n   pytest.mark.timeout(timeout=0, method=DEFAULT_METHOD)\n\nYou can use either positional or keyword arguments for both the\ntimeout and the method.  Neither needs to be present.\n\nSee the marker api documentation_ and examples_ for the various ways\nmarkers can be applied to test items.\n\n.. _documentation: https://docs.pytest.org/en/latest/mark.html\n\n.. _examples: https://docs.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules\n\n\nTimeouts in Fixture Teardown\n============================\n\nThe plugin will happily terminate timeouts in the finalisers of\nfixtures.  The timeout specified applies to the entire process of\nsetting up fixtures, running the tests and finalising the fixtures.\nHowever when a timeout occurs in a fixture finaliser and the test\nsuite continues, i.e. the signal method is used, it must be realised\nthat subsequent fixtures which need to be finalised might not have\nbeen executed, which could result in a broken test-suite anyway.  In\ncase of doubt the thread method which terminates the entire process\nmight result in clearer output.\n\nAvoiding timeouts in Fixtures\n=============================\n\nThe timeout applies to the entire test including any fixtures which\nmay need to be setup or torn down for the test (the exact affected\nfixtures depends on which scope they are and whether other tests will\nstill use the same fixture).  If the timeouts really are too short to\ninclude fixture durations, firstly make the timeouts larger ;).  If\nthis really isn't an option a ``timeout_func_only`` boolean setting\nexists which can be set in the pytest ini configuration file, as\ndocumented in ``pytest --help``.\n\n\nDebugger Detection\n==================\n\nThis plugin tries to avoid triggering the timeout when a debugger is\ndetected.  This is mostly a convenience so you do not need to remember\nto disable the timeout when interactively debugging.\n\nThe way this plugin detects whether or not a debugging session is\nactive is by checking if a trace function is set and if one is, it\ncheck to see if the module it belongs to is present in a set of known\ndebugging frameworks modules OR if pytest itself drops you into a pdb\nsession using ``--pdb`` or similar.\n\nThis functionality can be disabled with the ``--disable-debugger-detection`` flag\nor the corresponding ``timeout_disable_debugger_detection`` ini setting / environment\nvariable.\n\n\nExtending pytest-timeout with plugins\n=====================================\n\n``pytest-timeout`` provides two hooks that can be used for extending the tool.  These\nhooks are used for setting the timeout timer and cancelling it if the timeout is not\nreached.\n\nFor example, ``pytest-asyncio`` can provide asyncio-specific code that generates better\ntraceback and points on timed out ``await`` instead of the running loop iteration.\n\nSee `pytest hooks documentation\n<https://docs.pytest.org/en/latest/how-to/writing_hook_functions.html>`_ for more info\nregarding to use custom hooks.\n\n``pytest_timeout_set_timer``\n----------------------------\n\n.. code:: python\n\n   @pytest.hookspec(firstresult=True)\n   def pytest_timeout_set_timer(item, settings):\n       \"\"\"Called at timeout setup.\n\n       'item' is a pytest node to setup timeout for.\n\n       'settings' is Settings namedtuple (described below).\n\n       Can be overridden by plugins for alternative timeout implementation strategies.\n       \"\"\"\n\n\n``Settings``\n------------\n\nWhen ``pytest_timeout_set_timer`` is called, ``settings`` argument is passed.\n\nThe argument has ``Settings`` namedtuple type with the following fields:\n\n+-----------+-------+--------------------------------------------------------+\n|Attribute  | Index | Value                                                  |\n+===========+=======+========================================================+\n| timeout   | 0     | timeout in seconds or ``None`` for no timeout          |\n+-----------+-------+--------------------------------------------------------+\n| method    | 1     | Method mechanism,                                      |\n|           |       | ``'signal'`` and ``'thread'`` are supported by default |\n+-----------+-------+--------------------------------------------------------+\n| func_only | 2     | Apply timeout to test function only if ``True``,       |\n|           |       |  wrap all test function and its fixtures otherwise     |\n+-----------+-------+--------------------------------------------------------+\n\n``pytest_timeout_cancel_timer``\n-------------------------------\n\n.. code:: python\n\n   @pytest.hookspec(firstresult=True)\n   def pytest_timeout_cancel_timer(item):\n       \"\"\"Called at timeout teardown.\n\n       'item' is a pytest node which was used for timeout setup.\n\n       Can be overridden by plugins for alternative timeout implementation strategies.\n       \"\"\"\n\n``is_debugging``\n----------------\n\nWhen the timeout occurs, user can open the debugger session. In this case, the timeout\nshould be discarded.  A custom hook can check this case by calling ``is_debugging()``\nfunction:\n\n.. code:: python\n\n   import pytest\n   import pytest_timeout\n\n\n   def on_timeout():\n       if pytest_timeout.is_debugging():\n           return\n       pytest.fail(\"+++ Timeout +++\")\n\n\nChangelog\n=========\n\n2.2.0\n-----\n\n- Add ``--timeout-disable-debugger-detection`` flag, thanks\n  Michael Peters\n\n2.1.0\n-----\n\n- Get terminal width from shutil instead of deprecated py, thanks\n  Andrew Svetlov.\n- Add an API for extending ``pytest-timeout`` functionality\n  with third-party plugins, thanks Andrew Svetlov.\n\n2.0.2\n-----\n\n- Fix debugger detection on OSX, thanks Alexander Pacha.\n\n2.0.1\n-----\n\n- Fix Python 2 removal, thanks Nicusor Picatureanu.\n\n2.0.0\n-----\n\n- Increase pytest requirement to >=5.0.0.  Thanks Dominic Davis-Foster.\n- Use thread timeout method when plugin is not called from main\n  thread to avoid crash.\n- Fix pycharm debugger detection so timeouts are not triggered during\n  debugger usage.\n- Dropped support for Python 2, minimum pytest version supported is 5.0.0.\n\n1.4.2\n-----\n\n- Fix compatibility when run with pytest pre-releases, thanks\n  Bruno Oliveira,\n- Fix detection of third-party debuggers, thanks Bruno Oliveira.\n\n1.4.1\n-----\n\n- Fix coverage compatibility which was broken by 1.4.0.\n\n1.4.0\n-----\n\n- Better detection of when we are debugging, thanks Mattwmaster58.\n\n1.3.4\n-----\n\n- Give the threads a name to help debugging, thanks Thomas Grainger.\n- Changed location to https://github.com/pytest-dev/pytest-timeout\n  because bitbucket is dropping mercurial support.  Thanks Thomas\n  Grainger and Bruno Oliveira.\n\n1.3.3\n-----\n\n- Fix support for pytest >= 3.10.\n\n1.3.2\n-----\n\n- This changelog was omitted for the 1.3.2 release and was added\n  afterwards.  Apologies for the confusion.\n- Fix pytest 3.7.3 compatibility.  The capture API had changed\n  slightly and this needed fixing.  Thanks Bruno Oliveira for the\n  contribution.\n\n1.3.1\n-----\n\n- Fix deprecation warning on Python 3.6.  Thanks Micka\u00ebl Schoentgen\n- Create a valid tag for the release.  Somehow this didn't happen for\n  1.3.0, that tag points to a non-existing commit.\n\n1.3.0\n-----\n\n- Make it possible to only run the timeout timer on the test function\n  and not the whole fixture setup + test + teardown duration.  Thanks\n  Pedro Algarvio for the work!\n- Use the new pytest marker API, Thanks Pedro Algarvio for the work!\n\n1.2.1\n-----\n\n- Fix for pytest 3.3, thanks Bruno Oliveira.\n- Update supported python versions:\n  - Add CPython 3.6.\n  - Drop CPyhon 2.6 (as did pytest 3.3)\n  - Drop CPyhon 3.3\n  - Drop CPyhon 3.4\n\n1.2.0\n-----\n\n* Allow using floats as timeout instead of only integers, thanks Tom\n  Myers.\n\n1.1.0\n-----\n\n* Report (default) timeout duration in header, thanks Holger Krekel.\n\n1.0.0\n-----\n\n* Bump version to 1.0 to commit to semantic versioning.\n* Fix issue #12: Now compatible with pytest 2.8, thanks Holger Krekel.\n* No longer test with pexpect on py26 as it is no longer supported\n* Require pytest 2.8 and use new hookimpl decorator\n\n0.5\n---\n\n* Timeouts will no longer be triggered when inside an interactive pdb\n  session started by ``pytest.set_trace()`` / ``pdb.set_trace()``.\n\n* Add pypy3 environment to tox.ini.\n\n* Transfer repository to pytest-dev team account.\n\n0.4\n---\n\n* Support timeouts happening in (session scoped) finalizers.\n\n* Change command line option --timeout_method into --timeout-method\n  for consistency with pytest\n\n0.3\n---\n\n* Added the PYTEST_TIMEOUT environment variable as a way of specifying\n  the timeout (closes issue #2).\n\n* More flexible marker argument parsing: you can now specify the\n  method using a positional argument.\n\n* The plugin is now enabled by default.  There is no longer a need to\n  specify ``timeout=0`` in the configuration file or on the command\n  line simply so that a marker would work.\n\n\n0.2\n---\n\n* Add a marker to modify the timeout delay using a @pytest.timeout(N)\n  syntax, thanks to Laurant Brack for the initial code.\n\n* Allow the timeout marker to select the timeout method using the\n  ``method`` keyword argument.\n\n* Rename the --nosigalrm option to --method=thread to future proof\n  support for eventlet and gevent.  Thanks to Ronny Pfannschmidt for\n  the hint.\n\n* Add ``timeout`` and ``timeout_method`` items to the configuration\n  file so you can enable and configure the plugin using the ini file.\n  Thanks to Holger Krekel and Ronny Pfannschmidt for the hints.\n\n* Tested (and fixed) for python 2.6, 2.7 and 3.2.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pytest plugin to abort hanging tests",
    "version": "2.2.0",
    "project_urls": {
        "Homepage": "https://github.com/pytest-dev/pytest-timeout"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e23eabfdb7319d71a179bb8f5980e211d93e7db03f0c0091794dbcd652d642da",
                "md5": "06df07ef13f1fb5044e5fa422a7f2ccf",
                "sha256": "bde531e096466f49398a59f2dde76fa78429a09a12411466f88a07213e220de2"
            },
            "downloads": -1,
            "filename": "pytest_timeout-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "06df07ef13f1fb5044e5fa422a7f2ccf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 13142,
            "upload_time": "2023-10-08T10:14:23",
            "upload_time_iso_8601": "2023-10-08T10:14:23.014944Z",
            "url": "https://files.pythonhosted.org/packages/e2/3e/abfdb7319d71a179bb8f5980e211d93e7db03f0c0091794dbcd652d642da/pytest_timeout-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ab08e3182e9ed65ad5b247f9d13769f214fc52b0d3522c3e1c8dbfa2f879e5a",
                "md5": "888263c4bf3025ef1c4128a58861e6f6",
                "sha256": "3b0b95dabf3cb50bac9ef5ca912fa0cfc286526af17afc806824df20c2f72c90"
            },
            "downloads": -1,
            "filename": "pytest-timeout-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "888263c4bf3025ef1c4128a58861e6f6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 16391,
            "upload_time": "2023-10-08T10:14:25",
            "upload_time_iso_8601": "2023-10-08T10:14:25.196773Z",
            "url": "https://files.pythonhosted.org/packages/2a/b0/8e3182e9ed65ad5b247f9d13769f214fc52b0d3522c3e1c8dbfa2f879e5a/pytest-timeout-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-08 10:14:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-timeout",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-timeout"
}
        
Elapsed time: 0.17892s