Skip to content

Commit

Permalink
Use Path() instead of str for path comparison
Browse files Browse the repository at this point in the history
On Windows specifically is common to have drives diverging just by
casing ("C:" vs "c:"), depending on the cwd provided by the user.
  • Loading branch information
nicoddemus committed May 30, 2020
1 parent b98aa19 commit 757bded
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/_pytest/nodes.py
Expand Up @@ -29,6 +29,7 @@
from _pytest.mark.structures import MarkDecorator
from _pytest.mark.structures import NodeKeywords
from _pytest.outcomes import fail
from _pytest.pathlib import Path
from _pytest.store import Store

if TYPE_CHECKING:
Expand Down Expand Up @@ -361,8 +362,14 @@ def _repr_failure_py(
else:
truncate_locals = True

# excinfo.getrepr() formats paths relative to the CWD if `abspath` is False.
# It is possible for a fixture/test to change the CWD while this code runs, which
# would then result in the user seeing confusing paths in the failure message.
# To fix this, if the CWD changed, always display the full absolute path.
# It will be better to just always display paths relative to invocation_dir, but
# this requires a lot of plumbing (#6428).
try:
abspath = os.getcwd() != str(self.config.invocation_dir)
abspath = Path(os.getcwd()) != Path(self.config.invocation_dir)
except OSError:
abspath = True

Expand Down

0 comments on commit 757bded

Please sign in to comment.