pytest-dev / pytest-dev/pytest

Confusing test summary when using subtests

Open
#13,905 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: subtests
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Problem

The current summary format double-counts failures by adding test-level failures to subtest-level failures.

Scenario: Running 3 tests:

  • Test A: no subtests, fails
  • Test B: 3 subtests, all pass
  • Test C: 3 subtests, 1 fails and 2 pass

Current output:

With pytest -q:

3 failed, 1 passed, 5 subtests passed in 0.03s

With pytest:

3 failed, 1 passed in 0.03s

Why this is misleading:

The "3 failed" adds:

  • 2 regular test failure (Test A and C)
  • 1 failed subtests (in Test C)

This double-counts Test C's failure at both the test level and subtest level, making it unclear how much actually failed.

Suggested improvements

Several options to make the summary clearer:

  1. Omit subtests from summary:
    2 failed, 1 passed
    this assumes the division is by tests. a failed test with 1000 failed subtests and 1000 passing subtests will still show as 1 fail.

  2. Like 1, but add the subtests counts (maybe in parentheses):
    2 failed, 1 passed (1 subtest failed)
    or
    2 failed, 1 passed (1 subtest failed, 5 subtests passed)

  3. Treat each subtest as an individual test:
    2 failed, 5 passed
    This count each subtest execution as a separate test result. In this case: A (failed) + C.1 (failed) vs B.1, B.2, B.3, C.2, C.3 (all passed). This approach treats subtests equivalently to regular tests.

Environment

pytest 9.0.0

Reproduction

def test_fail():
    assert False

def test_pass(subtests):
    for i in range(3):
        with subtests.test(msg="all pass", i=i):
            assert True

def test_mixed(subtests):
    for i in range(3):
        with subtests.test(msg="1 fail", i=i):
            assert i != 0

Run with pytest -q to see the summary line.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction with pytest -q and pytest to compare the current summaries. Review how test-level and subtest-level results are counted, then choose and document a consistent summary format that avoids double-counting while preserving useful subtest counts. Done means the example produces an unambiguous summary and the relevant tests cover the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.