From 6951af3c6bf310c1b0b317cd71235aca077a2969 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 26 Jun 2022 10:06:18 -0300 Subject: [PATCH] Fix incorrect usage of os.path.sep in rewrite.py os.path.sep is not an official API, and is probably result of it being imported (and so available), however it seems that is not the case on all systems, I git blamed this on me, and I'm sure it was an accident (I probably meant `os.sep.join`), but let's go with `os.path.join` as that's the sane thing to do. Fix #9791 --- changelog/9791.bugfix.rst | 1 + src/_pytest/assertion/rewrite.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/9791.bugfix.rst diff --git a/changelog/9791.bugfix.rst b/changelog/9791.bugfix.rst new file mode 100644 index 00000000000..f81c870165b --- /dev/null +++ b/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. diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 81096764e04..7a55ff0eeed 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -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(os.path.join(*parts) + ".py") for pat in self.fnpats: # if the pattern contains subdirectories ("tests/**.py" for example) we can't bail out based