File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -447,6 +447,8 @@ def _prunetraceback(self, excinfo):
447447def _check_initialpaths_for_relpath (session , fspath ):
448448 for initial_path in session ._initialpaths :
449449 if fspath .common (initial_path ) == initial_path :
450+ if initial_path .isdir ():
451+ return fspath .relto (initial_path )
450452 return fspath .relto (initial_path .dirname )
451453
452454
Original file line number Diff line number Diff line change 1+ import py
2+
13import pytest
24from _pytest import nodes
35
@@ -29,3 +31,19 @@ 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+ d = py .path .local ()
39+
40+ class FakeSession :
41+ _initialpaths = [d ]
42+
43+ assert nodes ._check_initialpaths_for_relpath (FakeSession , d ) == ""
44+
45+ f = d .join ("file" )
46+ assert nodes ._check_initialpaths_for_relpath (FakeSession , f ) == "file"
47+
48+ outside = py .path .local ("/outside" )
49+ assert nodes ._check_initialpaths_for_relpath (FakeSession , outside ) is None
You can’t perform that action at this time.
0 commit comments