Repository navigation
Honor --lfnf=none when no selected test previously failed - #15417
cleissonom wants to merge 1 commit into
Conversation
A nonempty lastfailed cache can contain only removed or unselected tests. In that case --lf fell back to running every selected item even when the caller explicitly requested none. Co-authored-by: OpenAI GPT-6.2 Astra <noreply@openai.com>
|
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it. This change targets the wrong layer and leaves a dissonance in place.
#13614 lands in that branch for two different reasons:
With this PR the dissonance stays and gets worse:
Pruning stale entries is the more direct direction, but it is easy to get wrong too. A test that is missing from one run is not necessarily gone:
Each of these would silently forget a real failure, which is worse than the current symptom. Any pruning would have to be limited to cases where absence is certain, and it would need tests for each of these situations. So I don't think this can go in as is. The two cases should be separated: the semantics question for case 1 needs a decision on #13614 first, and a fix for case 2 needs a careful definition of when an entry is actually stale. Generated by Claude Code |
|
Thanks for the detailed review. I checked the rename case: with this patch, a renamed test that still fails is deselected on every I agree the two cases need to be handled separately. The |
Closes #13614.
Scope under discussion
Maintainer feedback distinguishes two cases: stale cache entries left by deleted or renamed tests, and real failures that still exist outside the current selection. The review identifies the latter's existing fallback as intentional and asks for a decision on #13614 before extending
--lfnf=noneto it.The current patch at
3eafe99bbtreats both cases the same. It does not remove stale entries or establish that an unselected test no longer exists. That distinction remains unresolved in this version.Change and regression coverage
In the original reproduction, removing a failing test leaves its node ID in the last-failed cache. Because the cache is nonempty,
pytest --lf --lfnf=noneenters the branch for known failures outside the selection and runs the remaining passing test.This patch adds a check for
--lfand--lfnf=nonewhen none of the selected items match a cached failure. It reports the remaining items throughpytest_deselectedand clears the items list. The fallback for plain--lfis unchanged.The added assertions extend
test_lastfailed_with_all_filtered. After the failing test is removed,--lf --lfnf=nonereports one deselected test and exits withExitCode.NO_TESTS_COLLECTED(5). The existing--lf --coassertions check that the remaining test is still collected under the default behavior.The added assertions cover the deleted-test example. They do not add separate coverage for failures excluded with
-kor--pyargs, and they do not validate cache cleanup.Validation and AI assistance
OpenAI GPT-6.2 Astra in OpenCode prepared the patch, regression test and initial PR text. The agent reported reproducing the behavior on pytest 9.2.0 and
main.At
3eafe99bb, it reported running all 68 cacheprovider tests andtox -e linting,py313on macOS with CPython 3.13.15. Linting passed. The full suite reported 4,753 passed, 52 skipped, 15 xfailed, 5 xpassed and 2 warnings.Cleisson reviewed the patch and approved it for submission.