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

Fix PytestPluginManager._is_in_confcutdir on Windows #12006

Closed

Conversation

nicoddemus
Copy link
Member

On Windows two paths might be in different drives, so if a path is not one of the parents of the confcutdir, it does not necessarily mean it is inside the confcutdir either.

Use Path.is_relative_to instead which directly answers that question for us.

The previous implementation could cause pytest to inspect all the parent paths of a path from one drive if pytest was invoked from another drive.

Moved the implementation to a function because it would be too convoluted to test the PytestPluginManager._is_in_confcutdir method directly.

On Windows two paths might be in different drives, so if a path is not one of the parents of the confcutdir, it does not necessarily mean it is inside the confcutdir either.

Use `Path.is_relative_to` instead which directly answers that question for us.

The previous implementation could cause pytest to inspect all the parent paths of a path from one drive if pytest was invoked from another drive.

Moved the implementation to a function because it would be too convoluted to test the `PytestPluginManager._is_in_confcutdir` method directly.
@nicoddemus
Copy link
Member Author

Heh this was actually done before, but it caused a regression: #9767.

The current behavior is definitely weird though.

@nicoddemus nicoddemus closed this Feb 18, 2024
@nicoddemus nicoddemus deleted the confcutdir-check-windows branch February 18, 2024 11:25
nicoddemus added a commit to nicoddemus/pytest that referenced this pull request Feb 18, 2024
Follow up to pytest-dev#12006, let's put some comments clarifying `is_in_confcutdir` semantics, as this is not the first time someone misunderstands it.

Also removed an obsolete comment in `_loadconftestmodules`: we already set the `confcutdir` based on `rootdir`/`initfile` if not explicitly given.
nicoddemus added a commit that referenced this pull request Feb 18, 2024
Follow up to #12006, let's put some comments clarifying `is_in_confcutdir` semantics, as this is not the first time someone misunderstands it.

Also removed an obsolete comment in `_loadconftestmodules`: we already set the `confcutdir` based on `rootdir`/`initfile` if not explicitly given.

Co-authored-by: Ran Benita <[email protected]>
flying-sheep pushed a commit to flying-sheep/pytest that referenced this pull request Apr 9, 2024
Follow up to pytest-dev#12006, let's put some comments clarifying `is_in_confcutdir` semantics, as this is not the first time someone misunderstands it.

Also removed an obsolete comment in `_loadconftestmodules`: we already set the `confcutdir` based on `rootdir`/`initfile` if not explicitly given.

Co-authored-by: Ran Benita <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant