Skip to content

Commit 1cf9e68

Browse files
committed
tests: cover absolute path handling in _compute_fixture_value
1 parent 18ac7e0 commit 1cf9e68

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/_pytest/fixtures.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,9 @@ def _compute_fixture_value(self, fixturedef):
550550
source_path = frameinfo.filename
551551
source_lineno = frameinfo.lineno
552552
source_path = py.path.local(source_path)
553-
if source_path.relto(funcitem.config.rootdir):
554-
source_path_str = source_path.relto(funcitem.config.rootdir)
553+
rel_source_path = source_path.relto(funcitem.config.rootdir)
554+
if rel_source_path:
555+
source_path_str = rel_source_path
555556
else:
556557
source_path_str = str(source_path)
557558
msg = (

testing/python/fixtures.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3662,13 +3662,30 @@ def test_foo(request):
36623662
" test_foos.py::test_foo",
36633663
"",
36643664
"Requested fixture 'fix_with_param' defined in:",
3665-
"*fix.py:4",
3665+
"{}:4".format(fixfile),
36663666
"Requested here:",
36673667
"test_foos.py:4",
36683668
"*1 failed*",
36693669
]
36703670
)
36713671

3672+
# With non-overlapping rootdir, passing tests_dir.
3673+
rootdir = testdir.mkdir("rootdir")
3674+
rootdir.chdir()
3675+
result = testdir.runpytest("--rootdir", rootdir, tests_dir)
3676+
result.stdout.fnmatch_lines(
3677+
[
3678+
"The requested fixture has no parameter defined for test:",
3679+
" test_foos.py::test_foo",
3680+
"",
3681+
"Requested fixture 'fix_with_param' defined in:",
3682+
"{}:4".format(fixfile),
3683+
"Requested here:",
3684+
"{}:4".format(testfile),
3685+
"*1 failed*",
3686+
]
3687+
)
3688+
36723689

36733690
def test_pytest_fixture_setup_and_post_finalizer_hook(testdir):
36743691
testdir.makeconftest(

0 commit comments

Comments
 (0)