From bfd801d8346d1af9342a2916dba98d06d6cb20b8 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 30 May 2020 20:01:01 -0300 Subject: [PATCH] Add comment as requested --- src/_pytest/nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index fe4a9296821..d604e463db9 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -360,6 +360,12 @@ 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 = Path(os.getcwd()) != Path(self.config.invocation_dir) except OSError: