pytest-timeout
A pytest plugin that terminates hanging or excessively slow tests and dumps a stack trace when it does
Repository Health
Technical Analysis
pytest-timeout is a pytest plugin that times every test and aborts it when it exceeds a configured duration, printing a stack dump of all running threads so you can diagnose why a test hung. It exists specifically to catch deadlocks and runaway tests in CI, not to enforce precise performance budgets — the README is explicit that timeouts should be a last resort, not an expected part of a healthy test suite.
Under the pytest-dev GitHub organization alongside pytest itself, the plugin supports two interruption strategies (a portable thread method and a POSIX signal method), configurable globally via --timeout, an ini setting, or the PYTEST_TIMEOUT environment variable, or per-test via the @pytest.mark.timeout() marker. With roughly 19 million weekly PyPI downloads, it’s one of the most widely installed pytest plugins for taming flaky or hanging test suites in continuous integration.
What You Get
- Global timeout configuration via
--timeoutCLI flag,PYTEST_TIMEOUTenv var, or the[pytest] timeoutini option - Per-test overrides via the
@pytest.mark.timeout(seconds)decorator marker - Two termination strategies: a portable
threadmethod and a faster POSIXsignal-based method - Automatic stack dumps of all running threads printed to stderr when a timeout fires
- Debugger detection that suppresses timeouts automatically during interactive
--pdbor breakpoint sessions - Two extension hooks (
pytest_timeout_set_timer/pytest_timeout_cancel_timer) for plugins like pytest-asyncio to customize timeout behavior
Common Use Cases
- Preventing a CI pipeline from hanging indefinitely when a test deadlocks or blocks on an unresponsive external call
- Diagnosing intermittent test hangs by inspecting the thread stack dump printed at timeout
- Setting a global safety-net timeout across a large test suite while overriding it per-test for known slow integration tests
- Combining with pytest-forked to fully isolate and recover from hard-terminated hanging tests
Under The Hood
Architecture — The entire plugin lives in a single ~550-line pytest_timeout.py module implementing pytest hook specifications (pytest_runtest_protocol, pytest_configure) that wrap each test item with a timer. The thread method spawns a watchdog thread that calls os._exit() on the whole process if the timer fires (hard termination, sacrificing teardown/JUnit output for certainty), while the signal method schedules a SIGALRM that raises inside the test via pytest’s own failure mechanism, allowing the suite to continue — a well-documented tradeoff spelled out in the README rather than hidden.
Tech Stack — Pure Python with zero runtime dependencies beyond pytest itself; the pyproject.toml build backend is plain setuptools. It targets Python 3.7+ and PyPy3, and CI covers a matrix of versions via tox.ini.
Code Quality — A single 658-line test_pytest_timeout.py test module (roughly matching the implementation’s line count) exercises both timeout methods, marker precedence, and debugger-detection behavior; ruff.toml and a pre-commit CI badge indicate linting is enforced. Development pace is slow but steady (0.33 commits/month recently, 274 total commits since 2019, moderate activity), consistent with a small, feature-complete utility rather than a churning codebase.
API Design — The public surface is intentionally tiny: a CLI flag, an ini option, an env var, and one marker, all converging on the same Settings namedtuple internally, which makes the common case (pytest --timeout=300) a one-line addition to any existing pytest invocation with no code changes required.
Used by 13 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Airbyte
Developer Tools · Data Engineering
Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.
ClickHouse
Databases · Analytics · Data Engineering
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
Dragonfly
Databases · Developer Tools · Devops
A modern Redis and Memcached replacement engineered for multi-core servers — delivering 25x more throughput, better cache hit rates, and up to 80% lower memory consumption with full API compatibility.
Flowfile
Data Engineering
Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.
Keep
Devops · Automation · Monitoring
The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.
Memgraph
Databases · AI Development
High-performance in-memory graph database for AI context and real-time analytics
nao
AI Development · Analytics
Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.
OpenHands
AI Code Assistants · AI Development
The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.