Skip to main content

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.

Example

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.md for pull requests, issue trackers, and terminals
  • pytest-why-report.html for 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.

Stop doomscrolling tracebacks. Run pytest --why.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_why-0.1.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_why-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_why-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_why-0.1.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pytest_why-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b741463ee9d419a4d48f3215cef230e7680b406bd4d10293a0c901c00685fd54
MD5 fd7eef95b03770445c065b3619fa1532
BLAKE2b-256 635d750c2b6706156ec6314227a0325010e47521e9bb16134aa8dac1cb694635

See more details on using hashes here.

File details

Details for the file pytest_why-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_why-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pytest_why-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 881aef16ef5591cb020a3f4238f92d2ece5a3ea7c7b383d5ae2292259b681065
MD5 ac9f689f8fcbd3e49726bb40a9b1bd8c
BLAKE2b-256 034f27ae78174a9870dc4c02fb8501e3f99c6af4d4d860a227d265535c5617db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page