Skip to content

Support rerunning on subtest errors in pytest 9.0 and newer#330

Open
flyser wants to merge 5 commits into
pytest-dev:masterfrom
flyser:master
Open

Support rerunning on subtest errors in pytest 9.0 and newer#330
flyser wants to merge 5 commits into
pytest-dev:masterfrom
flyser:master

Conversation

@flyser

@flyser flyser commented Jun 1, 2026

Copy link
Copy Markdown

This adds subtest support from pytest 9.0 to pytest-rerunfailures. Tests with failing subtests are handled as failed tests and are rerun completely (not the single subtest is run, but the full test). Resolves #315.

For transparency: Note that the _remove_failed_subtest_reports_from_stats() function is AI generated. The rest is human generated ;-)

@flyser flyser force-pushed the master branch 2 times, most recently from 8755a6f to ee003b3 Compare June 2, 2026 07:53
flyser added 2 commits June 2, 2026 16:01
Fixes:
 * Wrong color in the test summary, because pytest would only check the
   existance, but not the value of the 'failed' key in the tr.stats
 * Wrong count of the passed subtests

@icemac icemac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@icemac icemac enabled auto-merge (squash) June 3, 2026 07:00
@icemac icemac disabled auto-merge June 3, 2026 07:00
@icemac icemac requested a review from Copilot June 3, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support in pytest-rerunfailures for treating pytest 9+ subtest failures as test failures so the whole test is rerun, addressing the behavior reported in #315.

Changes:

  • Detect failed subtests (pytest 9.0+) and trigger reruns even when the main test report is not marked failed.
  • Clean up subtest failure state and terminal reporter stats when scheduling a rerun to avoid incorrect final tallies/exit status.
  • Add pytest 9+ subtest-focused regression tests and document the feature in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/pytest_rerunfailures.py Adds pytest 9 subtest integration, rerun decision logic, and cleanup of subtest-related state/stats across reruns.
tests/test_pytest_rerunfailures.py Adds regression tests for rerunning tests with failing subtests (pytest 9+ only).
CHANGES.rst Documents the new subtest rerun behavior and its pytest 9+ availability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_pytest_rerunfailures.py
Comment thread src/pytest_rerunfailures.py
@icemac

icemac commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@flyser Please re-review Copilot's comments.

@flyser

flyser commented Jun 3, 2026

Copy link
Copy Markdown
Author

Hi @icemac, done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests with failed subtests are not rerun

3 participants