Skip to content

Fix last-failed cache for unittest subtest failures - #15168

Open
Kerim-Sabic wants to merge 1 commit into
pytest-dev:mainfrom
Kerim-Sabic:fix/lastfailed-unittest-subtests
Open

Kerim-Sabic wants to merge 1 commit into
pytest-dev:mainfrom
Kerim-Sabic:fix/lastfailed-unittest-subtests

Conversation

@Kerim-Sabic

Copy link
Copy Markdown

Failed unittest.TestCase.subTest checks can disappear from the last-failed cache when a later subtest or the parent's call report passes. Consequently, --last-failed --lfnf=none can deselect a test that still fails.

Keep failures from SubtestReport until the parent call report has been processed. Consume the per-execution marker so a subsequent successful execution of the same node ID still clears its cached failure.

Closes #14575.

The regression tests cover passing and skipped reports after a failure, errors inside subtests, a skipped parent, operation without terminal reporting, rerunning with --last-failed, clearing the cache after repair, and repeated execution of one node ID.

Validation on Windows / Python 3.13.5:

  • tox -e linting: passed.
  • Final changed-file pre-commit hooks and git diff --cached --check: passed.
  • tox -e py313 -- -n 4 --basetemp=../pytest-test-tmp/full-py313-final: 4,615 passed, 145 skipped, 13 xfailed, 1 xpassed, and 1 failed. All 11 added regression cases passed.
  • The only failing test, test_fixture_doctest_skip_has_line_number, also fails at unchanged base commit aec0291ed14c724873bfcea99d5dfd739f75a68f in this environment.
  • Against unchanged production code, the final regression tests produce 10 failures from missing cache entries and one passing duplicate-execution control.

AI assistance: Codex helped investigate the report sequence, implement the change, and run validation. Kerim Sabic confirmed an in-depth review of the prepared patch and explanation before submission and is the human contributor responsible for the change.

  • Added regression tests.
  • Added changelog/14575.bugfix.rst.
  • Added Kerim Sabic to AUTHORS in alphabetical order.
  • Allow maintainers to push and squash commits.

No feature documentation is needed for this bugfix. AI assistance is disclosed above; optional AI coauthor trailers have not been added.

AI assistance: Codex helped investigate, implement, and validate this change. Kerim Sabic confirmed an in-depth review before upstream submission.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 12, 2026

This branch has not been deployed

No deployments
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