Skip to content

Commit 156a41a

Browse files
committed
Node.location: handle str with _node_location_to_relpath
1 parent 5e3994d commit 156a41a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/_pytest/nodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ def reportinfo(self) -> Tuple[Union[py.path.local, str], Optional[int], str]:
462462
@cached_property
463463
def location(self) -> Tuple[str, Optional[int], str]:
464464
location = self.reportinfo()
465-
assert isinstance(location[0], py.path.local), location[0]
466-
fspath = self.session._node_location_to_relpath(location[0])
465+
fspath = location[0]
466+
if not isinstance(fspath, py.path.local):
467+
fspath = py.path.local(fspath)
468+
fspath = self.session._node_location_to_relpath(fspath)
467469
assert type(location[2]) is str
468470
return (fspath, location[1], location[2])

testing/test_nose.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,12 @@ def test_raises_baseexception_caught():
395395
raise BaseException
396396
"""
397397
)
398-
result = testdir.runpytest()
398+
result = testdir.runpytest("-vv")
399399
result.stdout.fnmatch_lines(
400400
[
401+
"test_raises.py::test_raises_runtimeerror PASSED*",
402+
"test_raises.py::test_raises_baseexception_not_caught FAILED*",
403+
"test_raises.py::test_raises_baseexception_caught PASSED*",
401404
"*= FAILURES =*",
402405
"*_ test_raises_baseexception_not_caught _*",
403406
"",

0 commit comments

Comments
 (0)