Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cacheprovider: --lf file-skipping feature doesn't work for files in packages #11054

Closed
bluetech opened this issue May 29, 2023 · 1 comment · Fixed by #11055 or #11059
Closed

cacheprovider: --lf file-skipping feature doesn't work for files in packages #11054

bluetech opened this issue May 29, 2023 · 1 comment · Fixed by #11055 or #11059
Assignees
Labels
plugin: cache related to the cache builtin plugin topic: collection related to the collection phase type: bug problem that needs to be addressed

Comments

@bluetech
Copy link
Member

--lf has a feature where if a certain Module (python file) does not contain any failed tests, it is skipped entirely at the collector level instead of being collected and each item skipped individually. When this happens the collection summary looks like this:

run-last-failure: rerun previous 1 failure (skipped 1 file)

However, this feature doesn't work for Modules inside of Packages, only for those directly beneath the Session.

@bluetech bluetech added type: bug problem that needs to be addressed plugin: cache related to the cache builtin plugin topic: collection related to the collection phase labels May 29, 2023
@bluetech bluetech self-assigned this May 29, 2023
bluetech added a commit to bluetech/pytest that referenced this issue May 29, 2023
`--lf` has a feature where if a certain `Module` (python file) does not
contain any failed tests, it is skipped entirely at the collector level
instead of being collected and each item skipped individually. When this
happens the collection summary looks like this:

    run-last-failure: rerun previous 1 failure (skipped 1 file)

However, this feature didn't work for `Module`s inside of `Package`s,
only for those directly beneath the `Session`.

Fix pytest-dev#11054.
@bluetech
Copy link
Member Author

The fix in #11055 still doesn't cover all cases.

Problem

The file skipping works by keeping a set of all test files which had a failure (get_last_failed_paths), then skipping files which are not in it.

However, this skipping is only activated once at least one failure occurs, otherwise some Bad Things Happen (#6968?).

This means that if a clean file is collected before a file with known failures is collected, it won't be skipped, because the mechanism hasn't been activated yet.

So to prevent the previous item from occurring, the files are sorted such that files with known failures are collected first.

Unfortunately the sorting can only be done one collector at a time. So it is foiled by cases like this:

test_clean.py
pkg/__init__.py
pkg/test_failing.py

pkg is not sorted before test_clean.py because it is not a test file.

Proposed fix

While the whole feels like it can be done more robustly, I propose a simpler fix for now. Instead of get_last_failed_paths containing only test files (test_clean.py, pkg/test_failing.py), have it contain the directories as well (pkg). This way pkg is sorted before test_clean.py.

@bluetech bluetech reopened this May 30, 2023
bluetech added a commit to bluetech/pytest that referenced this issue May 30, 2023
bluetech added a commit to bluetech/pytest that referenced this issue May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: cache related to the cache builtin plugin topic: collection related to the collection phase type: bug problem that needs to be addressed
Projects
None yet
1 participant