Skip to content

Fix --last-failed with unittest subtests#14584

Open
sjh9714 wants to merge 1 commit into
pytest-dev:mainfrom
sjh9714:fix-lastfailed-subtests
Open

Fix --last-failed with unittest subtests#14584
sjh9714 wants to merge 1 commit into
pytest-dev:mainfrom
sjh9714:fix-lastfailed-subtests

Conversation

@sjh9714

@sjh9714 sjh9714 commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Fixes #14575.

Failed unittest.TestCase.subTest reports could be overwritten by later passing subtest or parent call reports in the last-failed cache, so --last-failed did not rerun the parent test. This keeps the parent node marked as failed when any subtest report fails, without changing the existing unittest subtest terminal summary behavior.

Changes

  • Preserve cache/lastfailed entries for tests that emitted a failed SubtestReport.
  • Add regression coverage for --last-failed with unittest.TestCase.subTest.
  • Add changelog fragment and AUTHORS entry.

Testing

  • python -m pytest testing/test_subtests.py::TestUnittestSubTest::test_last_failed -q
  • python -m pytest testing/test_subtests.py::test_subtests_last_failed_step_wise -q
  • python -m pytest testing/test_subtests.py::TestUnittestSubTest::test_last_failed testing/test_subtests.py::test_subtests_last_failed_step_wise -q
  • python -m ruff check src/_pytest/cacheprovider.py testing/test_subtests.py
  • python -m pytest testing/test_subtests.py -q
  • python -m pytest testing/test_cacheprovider.py::TestLastFailed testing/test_cacheprovider.py::test_cache_show -q
  • Manual reproduction from --last-failed does not (always?) see tests which failed in a subtest #14575: after an initial failing run, python -m pytest --lf --lfnf=none -q reran the parent unittest test and failed on the same subtests instead of deselecting everything.

Note: I used Codex while preparing this change, reviewed the final diff, and ran the listed checks locally.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--last-failed does not (always?) see tests which failed in a subtest

1 participant