File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 29
29
from _pytest .mark .structures import MarkDecorator
30
30
from _pytest .mark .structures import NodeKeywords
31
31
from _pytest .outcomes import fail
32
+ from _pytest .pathlib import Path
32
33
from _pytest .store import Store
33
34
34
35
if TYPE_CHECKING :
@@ -361,8 +362,14 @@ def _repr_failure_py(
361
362
else :
362
363
truncate_locals = True
363
364
365
+ # excinfo.getrepr() formats paths relative to the CWD if `abspath` is False.
366
+ # It is possible for a fixture/test to change the CWD while this code runs, which
367
+ # would then result in the user seeing confusing paths in the failure message.
368
+ # To fix this, if the CWD changed, always display the full absolute path.
369
+ # It will be better to just always display paths relative to invocation_dir, but
370
+ # this requires a lot of plumbing (#6428).
364
371
try :
365
- abspath = os .getcwd () != str (self .config .invocation_dir )
372
+ abspath = Path ( os .getcwd ()) != Path (self .config .invocation_dir )
366
373
except OSError :
367
374
abspath = True
368
375
You can’t perform that action at this time.
0 commit comments