{"id":3247,"library":"pytest-timeouts","title":"Pytest Timeouts Plugin","description":"pytest-timeouts is a Linux-only Pytest plugin (version 1.2.1) designed to precisely control the duration of various test case execution phases: setup, execution, and teardown. It's distinct from the `pytest-timeout` plugin and is specifically tailored for scenarios requiring SIGALRM-based test interruption on Linux systems. Releases are infrequent but active.","status":"active","version":"1.2.1","language":"en","source_language":"en","source_url":"https://github.com/Scony/pytest-timeouts","tags":["pytest","testing","timeout","plugin","linux-only","ci"],"install":[{"cmd":"pip install pytest-timeouts","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework; this is a plugin for pytest.","package":"pytest","optional":false}],"imports":[{"note":"Configuration is primarily done via pytest markers, command-line options, or pytest.ini, rather than direct imports of `pytest-timeouts` classes or functions.","symbol":"pytest.mark.<timeout_type>","correct":"import pytest\n\n@pytest.mark.execution_timeout(1.5)\ndef test_something():\n    ..."}],"quickstart":{"code":"import time\nimport pytest\n\n# Configure global timeouts in pytest.ini (optional):\n# [pytest]\n# setup_timeout = 0.3\n# execution_timeout = 0.5\n# teardown_timeout = 0.4\n\n@pytest.mark.setup_timeout(0.3)\n@pytest.mark.execution_timeout(0.5)\n@pytest.mark.teardown_timeout(0.4)\ndef test_timeout_phases():\n    print(\"\\nStarting setup (simulated)\")\n    time.sleep(0.1) # Simulate setup\n    print(\"Starting execution (simulated)\")\n    time.sleep(0.6) # This will exceed execution_timeout(0.5)\n    print(\"Starting teardown (simulated)\")\n    time.sleep(0.1) # Simulate teardown\n\ndef test_no_timeout():\n    print(\"\\nRunning test without explicit timeouts\")\n    time.sleep(0.1)\n\n# To run this test, save as test_example.py and execute:\n# pytest -v test_example.py","lang":"python","description":"This example demonstrates how to apply timeouts to the setup, execution, and teardown phases of a test using markers. The `test_timeout_phases` function's execution phase is intentionally set to exceed its defined timeout, which should cause a failure. You can also configure timeouts globally via `pytest.ini` or command-line options like `--setup-timeout`."},"warnings":[{"fix":"Ensure usage only on Linux environments or consider the more general `pytest-timeout` plugin if cross-platform compatibility is required.","message":"This plugin is explicitly 'Linux-only'. It relies on the SIGALRM signal, which is not reliably available or behaves differently on other operating systems like macOS or Windows. It will not function as expected on non-Linux platforms.","severity":"breaking","affected_versions":"All versions"},{"fix":"Be explicit about your desired timeout order using `--timeouts-order` if multiple configuration sources are used. Understand that command-line options generally override markers, which override `pytest.ini`.","message":"The `pytest-timeouts` plugin has a fixed order of precedence for applying timeout settings: command-line options (`opts`) > markers (`markers`) > `pytest.ini` (`ini`). This order can be customized or disabled using the `--timeouts-order` command-line option, e.g., `--timeouts-order oi` to prioritize `opts` then `ini` and disable markers.","severity":"gotcha","affected_versions":"All versions since 1.0.0"},{"fix":"Design tests to be robust against abrupt termination. If graceful teardown is critical, explore `pytest-forked` for process isolation or use the `thread` timeout method (if available and suitable for your tests, though `pytest-timeouts` primarily uses `SIGALRM`). Review the plugin's documentation on termination methods.","message":"When a test is terminated due to a timeout, especially with hard termination methods (like `os._exit()` which is often used), it may result in an abrupt exit without proper fixture teardown, incomplete JUnit XML output, or other post-test processing. While debugging information is usually preserved, be aware of these side-effects.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `pytest-timeouts` version 1.2.1 or newer to resolve `get_marker` warnings with `pytest 3.10.X`. Ensure your `pytest` version is compatible with the `pytest-timeouts` version you are using.","message":"Version 1.2.1 fixed a `PyTest get_marker warning` that specifically affected `pytest 3.10.X`. This indicates potential compatibility issues or warnings when using `pytest-timeouts` with specific `pytest` versions, particularly around how markers are accessed. Newer `pytest` versions generally prefer `request.node.get_closest_marker`.","severity":"deprecated","affected_versions":"<1.2.1 with pytest >=3.10.0"},{"fix":"Carefully choose the correct plugin based on your operating system and specific timeout requirements. If you need phase-specific timeouts on Linux, `pytest-timeouts` is the one. For general timeouts across platforms, `pytest-timeout` might be more appropriate.","message":"This plugin (`pytest-timeouts`) is distinct from the more widely known `pytest-timeout` plugin. `pytest-timeouts` is specifically designed for Linux and focuses on granular phase timeouts (setup, execution, teardown) using `SIGALRM`, whereas `pytest-timeout` offers broader OS support and different timeout mechanisms.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}