Skip to content

Commit

Permalink
Use PurePath directly instead of os.path.sep in rewrite.py
Browse files Browse the repository at this point in the history
Given we are already creating a `PurePath`, just pass the parts directly to it.

This avoids using `os.path.sep`, that although is an official API, seems not to be available in all systems.

Fix pytest-dev#9791
  • Loading branch information
nicoddemus committed Jun 27, 2022
1 parent 11fb5cd commit f92c4a7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/9791.bugfix.rst
@@ -0,0 +1 @@
Fixed a path handling code in ``rewrite.py`` that seems to work fine, but was incorrect and fails in some systems.
2 changes: 1 addition & 1 deletion src/_pytest/assertion/rewrite.py
Expand Up @@ -190,7 +190,7 @@ def _early_rewrite_bailout(self, name: str, state: "AssertionState") -> bool:
return False

# For matching the name it must be as if it was a filename.
path = PurePath(os.path.sep.join(parts) + ".py")
path = PurePath(*parts).with_suffix(".py")

for pat in self.fnpats:
# if the pattern contains subdirectories ("tests/**.py" for example) we can't bail out based
Expand Down

0 comments on commit f92c4a7

Please sign in to comment.