Skip to content

Commit e14ca19

Browse files
authored
Merge pull request #4352 from blueyed/_check_initialpaths_for_relpath
Fix nodes._check_initialpaths_for_relpath for dirs
2 parents e00f3a2 + bee72a6 commit e14ca19

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

src/_pytest/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def _prunetraceback(self, excinfo):
447447
def _check_initialpaths_for_relpath(session, fspath):
448448
for initial_path in session._initialpaths:
449449
if fspath.common(initial_path) == initial_path:
450-
return fspath.relto(initial_path.dirname)
450+
return fspath.relto(initial_path)
451451

452452

453453
class FSCollector(Collector):

testing/acceptance_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,11 @@ def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
663663
assert result.ret == 0
664664
result.stdout.fnmatch_lines(
665665
[
666-
"*test_hello.py::test_hello*PASSED*",
667-
"*test_hello.py::test_other*PASSED*",
668-
"*test_world.py::test_world*PASSED*",
669-
"*test_world.py::test_other*PASSED*",
670-
"*4 passed*",
666+
"test_hello.py::test_hello*PASSED*",
667+
"test_hello.py::test_other*PASSED*",
668+
"ns_pkg/world/test_world.py::test_world*PASSED*",
669+
"ns_pkg/world/test_world.py::test_other*PASSED*",
670+
"*4 passed in*",
671671
]
672672
)
673673

testing/test_nodes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import py
2+
13
import pytest
24
from _pytest import nodes
35

@@ -29,3 +31,23 @@ def test():
2931
)
3032
with pytest.raises(ValueError, match=".*instance of PytestWarning.*"):
3133
items[0].warn(UserWarning("some warning"))
34+
35+
36+
def test__check_initialpaths_for_relpath():
37+
"""Ensure that it handles dirs, and does not always use dirname."""
38+
cwd = py.path.local()
39+
40+
class FakeSession:
41+
_initialpaths = [cwd]
42+
43+
assert nodes._check_initialpaths_for_relpath(FakeSession, cwd) == ""
44+
45+
sub = cwd.join("file")
46+
47+
class FakeSession:
48+
_initialpaths = [cwd]
49+
50+
assert nodes._check_initialpaths_for_relpath(FakeSession, sub) == "file"
51+
52+
outside = py.path.local("/outside")
53+
assert nodes._check_initialpaths_for_relpath(FakeSession, outside) is None

testing/test_session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ def test_one():
323323

324324
result = testdir.runpytest("--rootdir={}".format(path))
325325
result.stdout.fnmatch_lines(
326-
["*rootdir: {}/root, inifile:*".format(testdir.tmpdir), "*1 passed*"]
326+
[
327+
"*rootdir: {}/root, inifile:*".format(testdir.tmpdir),
328+
"root/test_rootdir_option_arg.py *",
329+
"*1 passed*",
330+
]
327331
)
328332

329333

0 commit comments

Comments
 (0)