From 1cf9e68dbce51f512f3ed9197a8cdc67a9171ded Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 28 Jan 2020 18:39:47 +0100 Subject: [PATCH 1/2] tests: cover absolute path handling in _compute_fixture_value --- src/_pytest/fixtures.py | 5 +++-- testing/python/fixtures.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 464828de4..d70b2c64a 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -550,8 +550,9 @@ class FixtureRequest: source_path = frameinfo.filename source_lineno = frameinfo.lineno source_path = py.path.local(source_path) - if source_path.relto(funcitem.config.rootdir): - source_path_str = source_path.relto(funcitem.config.rootdir) + rel_source_path = source_path.relto(funcitem.config.rootdir) + if rel_source_path: + source_path_str = rel_source_path else: source_path_str = str(source_path) msg = ( diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 8cfaae50d..d9ea5cf58 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3662,13 +3662,30 @@ class TestParameterizedSubRequest: " test_foos.py::test_foo", "", "Requested fixture 'fix_with_param' defined in:", - "*fix.py:4", + "{}:4".format(fixfile), "Requested here:", "test_foos.py:4", "*1 failed*", ] ) + # With non-overlapping rootdir, passing tests_dir. + rootdir = testdir.mkdir("rootdir") + rootdir.chdir() + result = testdir.runpytest("--rootdir", rootdir, tests_dir) + result.stdout.fnmatch_lines( + [ + "The requested fixture has no parameter defined for test:", + " test_foos.py::test_foo", + "", + "Requested fixture 'fix_with_param' defined in:", + "{}:4".format(fixfile), + "Requested here:", + "{}:4".format(testfile), + "*1 failed*", + ] + ) + def test_pytest_fixture_setup_and_post_finalizer_hook(testdir): testdir.makeconftest( From 7c878742773d50e3bc04d1a5b0a786ce69562847 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 28 Jan 2020 19:02:35 +0100 Subject: [PATCH 2/2] source_path: py.path.local directly Via bc7282576. --- src/_pytest/fixtures.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index d70b2c64a..5d54078de 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -547,9 +547,8 @@ class FixtureRequest: if has_params: frame = inspect.stack()[3] frameinfo = inspect.getframeinfo(frame[0]) - source_path = frameinfo.filename + source_path = py.path.local(frameinfo.filename) source_lineno = frameinfo.lineno - source_path = py.path.local(source_path) rel_source_path = source_path.relto(funcitem.config.rootdir) if rel_source_path: source_path_str = rel_source_path