Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions neotest_python/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ def _get_short_output(
buffer.seek(0)
return buffer.read()

def _get_abs_path(self, file_path: Union[str, Path]):
try:
# rootpath is now the preferred way to access root
abs_path = str(self.pytest_config.rootpath / file_path)
except AttributeError:
# fallback to rootdir for older pytest versions
abs_path = str(Path(self.pytest_config.rootdir, file_path))
return abs_path

def pytest_deselected(self, items: List["pytest.Item"]):
for report in items:
file_path, *name_path = report.nodeid.split("::")
abs_path = str(Path(self.pytest_config.rootdir, file_path))
abs_path = self._get_abs_path(file_path)
*namespaces, test_name = name_path
valid_test_name, *params = test_name.split("[") # ]
pos_id = "::".join([abs_path, *(namespaces), valid_test_name])
Expand Down Expand Up @@ -108,7 +117,7 @@ def pytest_runtest_makereport(
return

file_path, *name_path = item.nodeid.split("::")
abs_path = str(Path(self.pytest_config.rootdir, file_path))
abs_path = self._get_abs_path(file_path)
*namespaces, test_name = name_path
valid_test_name, *params = test_name.split("[") # ]
pos_id = "::".join([abs_path, *namespaces, valid_test_name])
Expand Down