Fix collection failures due to permission errors when using --pyargs
#12043
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
--pyargs
and 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
pyargs
arguments 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
--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: