From 9dcdea5de7a9d7f3d24a59182682fa6a0fd59bdb Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 23 Jan 2020 13:25:15 +0100 Subject: [PATCH] Rewrite Item.location to be clearer with regard to types --- src/_pytest/nodes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 080f079cd..ab976efae 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -462,9 +462,10 @@ class Item(Node): @cached_property def location(self) -> Tuple[str, Optional[int], str]: location = self.reportinfo() - fspath = location[0] - if not isinstance(fspath, py.path.local): - fspath = py.path.local(fspath) - fspath = self.session._node_location_to_relpath(fspath) + if isinstance(location[0], py.path.local): + fspath = location[0] + else: + fspath = py.path.local(location[0]) + relfspath = self.session._node_location_to_relpath(fspath) assert type(location[2]) is str - return (fspath, location[1], location[2]) + return (relfspath, location[1], location[2])