Fix collection failures due to permission errors when using --pyargs#12043
Merged
bluetech merged 5 commits intopytest-dev:mainfrom Mar 2, 2024
Merged
Fix collection failures due to permission errors when using --pyargs#12043bluetech merged 5 commits intopytest-dev:mainfrom
--pyargs#12043bluetech merged 5 commits intopytest-dev:mainfrom
Conversation
Used in `resolve_collection_argument`. It's implicitly imported by some other import, but some type checkers don't recognize this.
nicoddemus
approved these changes
Mar 2, 2024
Member
nicoddemus
left a comment
There was a problem hiding this comment.
LGTM!
I specially liked the CollectionArgument dataclass, this is something that also caught my eye in the past.
Missing a CHANGELOG entry; I would add an example showing the old and the new collection tree, as it helps understand the change better.
In preparation of adding more info to it.
This is available when the argument is a `--pyargs` argument (resolved from a python module path). Will be used in an upcoming commit.
No logical change, preparation for the next commit.
…llection arguments
(diff better viewed ignoring whitespace)
In pytest<8, the collection tree for `pyargs` arguments in an invocation
like this:
pytest --collect-only --pyargs pyflakes.test.test_undefined_names
looked like this:
```
<Package test>
<Module test_undefined_names.py>
<UnitTestCase Test>
<TestCaseFunction test_annotationUndefined>
... snipped ...
```
The pytest 8 collection improvements changed it to this:
```
<Dir pytest>
<Dir .tox>
<Dir venv>
<Dir lib>
<Dir python3.11>
<Dir site-packages>
<Package pyflakes>
<Package test>
<Module test_undefined_names.py>
<UnitTestCase Test>
<TestCaseFunction test_annotationUndefined>
... snipped ...
```
Besides being egregious (and potentially even worse than the above,
going all the way to the root, for system-installed packages, as is
apparently common in CI), this also caused permission errors when trying
to probe some of those intermediate directories.
This change makes `--pyargs` arguments no longer try to add parent
directories to the collection tree according to the `--confcutdir` like
they're regular arguments. Instead, only add the parents that are in the
import path. This now looks like this:
```
<Package .tox/venv/lib/python3.11/site-packages/pyflakes>
<Package test>
<Module test_undefined_names.py>
<UnitTestCase Test>
<TestCaseFunction test_annotationUndefined>
... snipped ...
```
Fix pytest-dev#11904.
Member
Author
I never forget to forget to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should fix #11904. It does not fix all permission error situations that popped up with pytest 8.0.0 but most complaints were about
--pyargsand others are mostly misconfigurations as far I could tell, so let's start with this to unblock pytest 8.1.0 and see about the others as the come.The PR has some preparatory commits, here is the description of the main change (last commit):
In pytest<8, the collection tree for
pyargsarguments in an invocation like this:looked like this:
The pytest 8 collection improvements changed it to this:
Besides being egregious (and potentially even worse than the above, going all the way to the root, for system-installed packages, as is apparently common in CI), this also caused permission errors when trying to probe some of those intermediate directories.
This change makes
--pyargsarguments no longer try to add parent directories to the collection tree according to the--confcutdirlike they're regular arguments. Instead, only add the parents that are in the import path. This now looks like this: