pytest-threadleak
Detects thread leaks
Decision gist · record as of 2026-08-14
Yes, if you need to catch thread leaks in your tests. The plugin is simple, low-friction, and has no known vulnerabilities. However, be aware that maintenance is dormant; verify compatibility with your pytest and Python versions before relying on it in a critical pipeline. For most projects, the benefit of catching thread leaks outweighs the maintenance risk.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction; depends only on pytest.
- Maintenance is dormant—last release was 2022-07-03, though the repository remains active and has not been archived.
License · maintenance · safety
MIT (permissive) — MIT license (permissive); you may use, modify, and distribute this software freely with minimal restrictions.
last release 2022-07-03 (1503 days) · last repo commit 2024-09-01 · 11 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 240,664 downloads/mo, #8,902 on PyPI
Alternatives
Verify before relying
pip install pytest-threadleak
# In your test file or pytest.ini:
# pytest.ini:
# [pytest]
# threadleak = True
# Then run:
# pytest --threadleak your_test.py- Whether the plugin works correctly with modern pytest versions given the last release was 2022-07-03.
- Whether thread exclusion patterns (threadleak_exclude) work as documented with current Python threading internals.
- Performance impact when running large test suites with threadleak enabled.
What it is and what it does
pytest-threadleak is a pytest plugin that automatically detects when a test leaves threads running after it completes. It works by checking for leaked threads after each test and failing the test if any are found. You can enable it globally via pytest.ini, per-test using the @pytest.mark.threadleak decorator, or per-module. The plugin also supports excluding specific threads by regex pattern if certain background threads are expected.
The plugin helps catch both test bugs (tests that spawn threads without cleaning them up) and issues in the code being tested (libraries that leak threads). It integrates seamlessly into your pytest workflow and requires no changes to test code beyond optionally adding markers or configuration.
Use it for
- Catch tests that spawn background threads without properly joining or stopping them before test completion.
- Detect thread leaks in libraries under test that may cause resource exhaustion or test isolation problems.
- Enforce thread cleanup discipline across a test suite by enabling threadleak globally in pytest configuration.
- Exclude known background threads (e.g., connection pools) from leak detection using regex patterns.
- Debug test flakiness caused by threads from previous tests interfering with subsequent tests.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need to catch thread leaks in your tests.
The plugin is simple, low-friction, and has no known vulnerabilities. However, be aware that maintenance is dormant; verify compatibility with your pytest and Python versions before relying on it in a critical pipeline. For most projects, the benefit of catching thread leaks outweighs the maintenance risk.
Install
pytest-threadleak on PyPI
Before you install
Low install friction; depends only on pytest. Maintenance is dormant—last release was 2022-07-03, though the repository remains active and has not been archived.
License in practice
MIT license (permissive); you may use, modify, and distribute this software freely with minimal restrictions.
Quickstart
pip install pytest-threadleak
# In your test file or pytest.ini:
# pytest.ini:
# [pytest]
# threadleak = True
# Then run:
# pytest --threadleak your_test.py
Verify before relying
- Whether the plugin works correctly with modern pytest versions given the last release was 2022-07-03.
- Whether thread exclusion patterns (threadleak_exclude) work as documented with current Python threading internals.
- Performance impact when running large test suites with threadleak enabled.
Package facts
| License | MIT permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagepytest |
| Maintenance | Dormant 1,503 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 240,664 / month, #8,902 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing |
Evidence: pytest_threadleak-0.5.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytest thread leak detection”
- pytest-threadleakA pytest plugin that detects when tests leak threads—threads that…
- pyleakDetects leaked asyncio tasks, threads, and event loop blocking in…
- pytest-reraiseCaptures exceptions raised in threads during pytest tests and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also pytest-logging · pyleak · pytest-custom-exit-code · pytest-run-parallel · pytest-flakefinder · pytest-find-dependencies · pytest-monitor · pytest-replay · pytest-timeout · pytest-race