diff --git a/neotest_python/pytest.py b/neotest_python/pytest.py index a2371f3..d63290a 100644 --- a/neotest_python/pytest.py +++ b/neotest_python/pytest.py @@ -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]) @@ -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])