Skip to content

Commit 1bad70f

Browse files
committed
Add test and changelog for #6428
1 parent 958989f commit 1bad70f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

changelog/6428.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Paths appearing in error messages are now correct in case the current working directory has
2+
changed since the start of the session.

testing/test_nodes.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,30 @@ class FakeSession:
5151

5252
outside = py.path.local("/outside")
5353
assert nodes._check_initialpaths_for_relpath(FakeSession, outside) is None
54+
55+
56+
def test_failure_with_changed_cwd(testdir):
57+
"""
58+
Test failure lines should use absolute paths if cwd has changed since
59+
invocation, so the path is correct (#6428).
60+
"""
61+
p = testdir.makepyfile(
62+
"""
63+
import os
64+
import pytest
65+
66+
@pytest.fixture
67+
def private_dir():
68+
out_dir = 'ddd'
69+
os.mkdir(out_dir)
70+
old_dir = os.getcwd()
71+
os.chdir(out_dir)
72+
yield out_dir
73+
os.chdir(old_dir)
74+
75+
def test_show_wrong_path(private_dir):
76+
assert False
77+
"""
78+
)
79+
result = testdir.runpytest()
80+
result.stdout.fnmatch_lines([str(p) + ":*: AssertionError", "*1 failed in *"])

0 commit comments

Comments
 (0)