Skip to content

Commit

Permalink
Add test and changelog for pytest-dev#6428
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 30, 2020
1 parent fb9f277 commit b98aa19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog/6428.bugfix.rst
@@ -0,0 +1,2 @@
Paths appearing in error messages are now correct in case the current working directory has
changed since the start of the session.
27 changes: 27 additions & 0 deletions testing/test_nodes.py
Expand Up @@ -58,3 +58,30 @@ class FakeSession:

outside = py.path.local("/outside")
assert nodes._check_initialpaths_for_relpath(FakeSession, outside) is None


def test_failure_with_changed_cwd(testdir):
"""
Test failure lines should use absolute paths if cwd has changed since
invocation, so the path is correct (#6428).
"""
p = testdir.makepyfile(
"""
import os
import pytest
@pytest.fixture
def private_dir():
out_dir = 'ddd'
os.mkdir(out_dir)
old_dir = os.getcwd()
os.chdir(out_dir)
yield out_dir
os.chdir(old_dir)
def test_show_wrong_path(private_dir):
assert False
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines([str(p) + ":*: AssertionError", "*1 failed in *"])

0 comments on commit b98aa19

Please sign in to comment.