Skip to content

Add --lf-keep to retain last-failed test groups - #15494

Open
BforBex wants to merge 1 commit into
pytest-dev:mainfrom
BforBex:hw6b-issue-1017
Open

BforBex wants to merge 1 commit into
pytest-dev:mainfrom
BforBex:hw6b-issue-1017

Conversation

@BforBex

@BforBex BforBex commented Nov 28, 2026

Copy link
Copy Markdown

Summary

Addresses #1017.

Adds an opt-in --lf-keep modifier for --lf that retains previously failing tests until the entire failure group completes acceptably in one successful session.

Currently, ordinary --lf removes repaired tests from the last-failed cache individually. This can cause subsequent reruns to miss regressions in previously repaired tests while other failures remain unresolved.

Usage: pytest --lf --lf-keep

Implementation

  • Maintain a separate cache/lastfailed_group entry without changing ordinary last-failed cache semantics.
  • Retain repaired tests across partial selections, failures, and interrupted sessions.
  • Require acceptable execution-phase outcomes before expiring the group.
  • Handle serial collector recovery, including nested collectors and explicit node selections.
  • Add documentation, a command-line reference entry, and a changelog entry.

Testing

Added 23 regression test cases.

Validation Result
Cacheprovider tests 91 passed
Python 3.12 full default suite 4,792 passed, 51 skipped, 13 xfailed, 7 xpassed
Python 3.13 full default suite 4,792 passed, 51 skipped, 15 xfailed, 5 xpassed
tox -e linting Passed
tox -e docs Passed

Both full test suites completed with exit code 0.

Limitations and design considerations

Deleted or renamed retained node IDs are conservatively preserved until cache clearing.

Basic retained-group execution was tested with pytest-xdist using two local workers. However, recovery from previously failing collectors can leave collector placeholders cached because successful collection reports containing the recovered children are not available to the controller.

Ordinary distributed collector-cache persistence was also reproduced against unchanged upstream code. The retained-mode limitation is documented.

Feedback on the proposed CLI interface, same-session expiry semantics, and distributed recovery scope is welcome.

AI assistance

OpenAI Codex (GPT-6 model family, exact variant unavailable) and ChatGPT (GPT-6.2) assisted with research, design, implementation, testing, debugging, and documentation.

AI attribution is also included in the commit message. I will take responsibility for reviewing the contribution and responding to feedback.

This contribution was developed as part of a University of Michigan software engineering course.

Retain repaired tests alongside unresolved failures until the entire group completes acceptably in one successful session. Preserve ordinary last-failed cache semantics and handle partial selections conservatively.

Add regression tests, documentation, and a changelog entry for issue pytest-dev#1017.

Assisted-by: OpenAI Codex (GPT-6 family; exact model variant unavailable)
Assisted-by: ChatGPT (GPT-6.2)
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 28, 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.

1 participant