Skip to content

Commit 2d29c3e

Browse files
authored
Merge pull request #6604 from blueyed/tests-_compute_fixture_value-cover-abs-source_path_str
tests: cover absolute path handling in _compute_fixture_value
2 parents 18ac7e0 + 7c87874 commit 2d29c3e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/_pytest/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ def _compute_fixture_value(self, fixturedef):
547547
if has_params:
548548
frame = inspect.stack()[3]
549549
frameinfo = inspect.getframeinfo(frame[0])
550-
source_path = frameinfo.filename
550+
source_path = py.path.local(frameinfo.filename)
551551
source_lineno = frameinfo.lineno
552-
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)
552+
rel_source_path = source_path.relto(funcitem.config.rootdir)
553+
if rel_source_path:
554+
source_path_str = rel_source_path
555555
else:
556556
source_path_str = str(source_path)
557557
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)