pytest-timeout

A pytest plugin that terminates hanging or excessively slow tests and dumps a stack trace when it does

Tool
PyPI
v2.4.0
259 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
56 /100 Fair
Development Activity 48
Maintenance 20
Community 76
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 74
Code Quality 78
Innovation 65
Learning Curve 90

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 --timeout CLI flag, PYTEST_TIMEOUT env var, or the [pytest] timeout ini option
  • Per-test overrides via the @pytest.mark.timeout(seconds) decorator marker
  • Two termination strategies: a portable thread method and a faster POSIX signal-based method
  • Automatic stack dumps of all running threads printed to stderr when a timeout fires
  • Debugger detection that suppresses timeouts automatically during interactive --pdb or 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

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 5 days ago
Python
47%
Other

Airbyte

Data Engineering · Developer Tools

22,143

Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.

View details
95
Repo Health
80
Technical
67
Dependency
Built with
Python 47%
Kotlin 43%
Updated 5 days ago
C++
68%
Apache 2.0

ClickHouse

Analytics · Data Engineering · Databases

50,116

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
64
Dependency
Built with
C++ 68%
Python 14%
Updated 5 days ago
C++
73%
Other

Dragonfly

Databases · Developer Tools · Devops

31,706

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.

View details
90
Repo Health
9
Technical
71
Dependency
Built with
C++ 73%
Python 16%
Updated 6 days ago
Python
65%
MIT

Flowfile

Data Engineering

363

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python 65%
Vue 17%
TypeScript 17%
Updated 6 days ago
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,359

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.

View details
89
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 2 weeks ago
C++
66%
Other

Memgraph

AI Development · Databases

4,581

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
69
Dependency
Built with
C++ 66%
Python 18%
Updated 6 days ago
TypeScript
83%
Apache 2.0

nao

AI Development · Analytics

1,702

Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.

View details
84
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 83%
Python 17%
Updated 1 weeks ago
TypeScript
95%
Other

OpenHands

AI Code Assistants · AI Development

89,328

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.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 95%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers