### pytest_timeout_set_timer Hook Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst This hook is called at timeout setup for a given pytest node. It receives the node item and settings, allowing plugins to implement alternative timeout strategies. ```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. """ ``` -------------------------------- ### Combining Function and Session Timeouts Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Illustrates how to set both individual test function timeouts and an overall session timeout. This ensures both granular and global execution time limits are enforced. ```bash pytest --timeout=5 --session-timeout=100 ``` -------------------------------- ### pytest-timeout Version History and Features Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst This entry summarizes the evolution of the pytest-timeout plugin, highlighting key features and compatibility changes across different versions. It includes updates on Python version support, debugger integration, configuration methods, and API changes. ```python 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 ----- - 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. ``` -------------------------------- ### Per-Item Timeout Marker Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Illustrates setting a timeout for a specific test item using the 'timeout' marker. This allows for fine-grained control over test durations. ```python @pytest.mark.timeout(300) def test_foo(): pass ``` -------------------------------- ### Global Timeout in pytest Configuration Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Shows how to configure a global timeout for all tests in a pytest project by setting the 'timeout' option in the pytest configuration file (e.g., pytest.ini). ```ini [pytest] timeout = 300 ``` -------------------------------- ### Setting Session Timeout via Command Line Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Configures the total execution time for a pytest session using the --session-timeout command-line option. This limits the entire test run to a specified duration in seconds. ```bash pytest --session-timeout=600 ``` -------------------------------- ### Timeout Marker API Signature Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Shows the full signature for the pytest.mark.timeout marker, including default values for timeout duration and method. It highlights the flexibility in using positional or keyword arguments. ```python pytest.mark.timeout(timeout=0, method=DEFAULT_METHOD) ``` -------------------------------- ### Decorator for Individual Test Timeout Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Demonstrates how to use the `@pytest.mark.timeout` decorator to set a specific timeout for an individual test function. This timeout overrides any global timeout settings. ```python import pytest @pytest.mark.timeout(60) def test_foo(): pass ``` -------------------------------- ### Using Timeout Marker with Method Override Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Demonstrates how to specify the 'thread' method for a timeout using the pytest marker decorator. This is useful when the default 'signal' method might interfere with the code under test. ```python @pytest.mark.timeout(method="thread") def test_foo(): pass ``` -------------------------------- ### Timeout Marker with Func Only Override Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Illustrates how to use the 'func_only' parameter within the timeout marker to ensure the timeout only applies to the test function itself, overriding the 'timeout_func_only' setting in the pytest configuration file. ```python @pytest.mark.timeout(60, func_only=True) def test_foo(): pass ``` -------------------------------- ### Setting Session Timeout in pytest.ini Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Defines the session timeout duration within the pytest configuration file. This provides a persistent way to set the overall test execution time limit. ```ini [pytest] session_timeout = 600 ``` -------------------------------- ### Debugging Timeout Handling Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst Demonstrates how to check if the current execution is within a debugger session to potentially discard timeouts. This prevents unexpected interruptions during debugging. ```python import pytest import pytest_timeout def on_timeout(): if pytest_timeout.is_debugging(): return pytest.fail("+++ Timeout +++") ``` -------------------------------- ### pytest_timeout_cancel_timer Hook Source: https://github.com/pytest-dev/pytest-timeout/blob/main/README.rst This hook is called at timeout teardown for a given pytest node. It allows plugins to clean up or perform actions after a timeout has been handled. ```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. """ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.