A pytest plugin that explains failing tests like a senior engineer.
Project description
pytest-why
A pytest plugin that explains failing tests like a senior engineer.
pytest-why turns common pytest failures into concise explanations and practical
next steps. It runs locally, adds no noise to normal test runs, and creates
shareable Markdown and HTML reports when you ask for them.
Install
python -m pip install pytest-why
For local development:
python -m pip install -e .[dev]
Usage
Run pytest with one extra flag:
python -m pytest --why
Without --why, the plugin does nothing and creates no report files.
Viral demo
Given:
def test_math():
assert 2 + 2 == 5
Run:
pytest --why
Sample output:
================ pytest-why: failure explanations ================
Total failures: 1
Assertion mismatch: test_math.py::test_math (call)
Why: The code ran, but the observed value or state did not match what the test expected.
Hint: Compare the expected and actual values near the final assertion, then trace where they first diverge.
Reports: pytest-why-report.md, pytest-why-report.html
Reports
Each --why run writes:
pytest-why-report.mdfor pull requests, issue trackers, and terminalspytest-why-report.htmlfor a styled, standalone browser view
Both reports include the failing test, pytest phase, classification, duration, explanation, hint, and the complete raw traceback.
Supported classifications
- Assertion mismatch: expected and actual values differ
- Import error: a module or symbol could not be imported
- Fixture error: missing fixtures, scope mismatches, or recursive dependencies
- Timeout: a test or operation exceeded its time limit
- Unknown failure: deterministic fallback with traceback-first guidance
Selenium and Playwright tracebacks also receive a focused browser automation hint covering selectors, waits, page timing, and element visibility.
The MVP is deterministic and local. No LLM or network connection is required.
Stop doomscrolling tracebacks. Run pytest --why.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_why-0.1.0.tar.gz.
File metadata
- Download URL: pytest_why-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f534a18e542bb4360ca53ab333b634c5b24befe4eb5551dc89b1b06423f24bc4
|
|
| MD5 |
57a00f349dffee180d6a7c5696d6e538
|
|
| BLAKE2b-256 |
a59b959297f25960bb87d3e6e95dde438d06eb1829242bb4a8ac6ffa9a963219
|
File details
Details for the file pytest_why-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_why-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26bb66c8f05140381cc335b03edaa80a11e1f0afb4c9b8e8ba8a466363241a89
|
|
| MD5 |
3a769ae8d27aa8800d606fb7c69cb753
|
|
| BLAKE2b-256 |
48caafc8e6485eb59f19b1a97ceb195b5f2584440631cc5b90e77c81360a1bd8
|