diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index fc951d2bc..080f079cd 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -462,7 +462,9 @@ class Item(Node): @cached_property def location(self) -> Tuple[str, Optional[int], str]: location = self.reportinfo() - assert isinstance(location[0], py.path.local), location[0] - fspath = self.session._node_location_to_relpath(location[0]) + fspath = location[0] + if not isinstance(fspath, py.path.local): + fspath = py.path.local(fspath) + fspath = self.session._node_location_to_relpath(fspath) assert type(location[2]) is str return (fspath, location[1], location[2]) diff --git a/testing/test_nose.py b/testing/test_nose.py index 15be7b73a..b6200c6c9 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -395,9 +395,12 @@ def test_raises(testdir): raise BaseException """ ) - result = testdir.runpytest() + result = testdir.runpytest("-vv") result.stdout.fnmatch_lines( [ + "test_raises.py::test_raises_runtimeerror PASSED*", + "test_raises.py::test_raises_baseexception_not_caught FAILED*", + "test_raises.py::test_raises_baseexception_caught PASSED*", "*= FAILURES =*", "*_ test_raises_baseexception_not_caught _*", "",