From ba7069a03001dcb23e87a0e803da766ee8f7160c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Mon, 31 Oct 2022 14:14:52 +0000 Subject: [PATCH] fix(pytest): don't reverse namespaces See #26 --- neotest_python/base.py | 1 - neotest_python/pytest.py | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/neotest_python/base.py b/neotest_python/base.py index 9e2975c..b0b7df3 100644 --- a/neotest_python/base.py +++ b/neotest_python/base.py @@ -31,7 +31,6 @@ else: class NeotestAdapter(abc.ABC): - def update_result( self, base: Optional[NeotestResult], update: NeotestResult ) -> NeotestResult: diff --git a/neotest_python/pytest.py b/neotest_python/pytest.py index 47d0384..979200c 100644 --- a/neotest_python/pytest.py +++ b/neotest_python/pytest.py @@ -10,7 +10,6 @@ if TYPE_CHECKING: class PytestNeotestAdapter(NeotestAdapter): - def run( self, args: List[str], @@ -24,7 +23,6 @@ class PytestNeotestAdapter(NeotestAdapter): class NeotestResultCollector: - def __init__( self, adapter: PytestNeotestAdapter, @@ -33,10 +31,12 @@ class NeotestResultCollector: self.stream = stream self.adapter = adapter - self.pytest_config: "Config" = None # type: ignore + self.pytest_config: "Config" = None # type: ignore self.results: Dict[str, NeotestResult] = {} - def _get_short_output(self, config: "Config", report: "TestReport") -> Optional[str]: + def _get_short_output( + self, config: "Config", report: "TestReport" + ) -> Optional[str]: from _pytest.terminal import TerminalReporter buffer = StringIO() @@ -62,9 +62,9 @@ class NeotestResultCollector: for report in items: file_path, *name_path = report.nodeid.split("::") abs_path = str(Path(self.pytest_config.rootdir, file_path)) - test_name, *namespaces = reversed(name_path) + *namespaces, test_name = name_path valid_test_name, *params = test_name.split("[") # ] - pos_id = "::".join([abs_path, *namespaces, valid_test_name]) + pos_id = "::".join([abs_path, *(namespaces), valid_test_name]) result = self.adapter.update_result( self.results.get(pos_id), { @@ -88,7 +88,7 @@ class NeotestResultCollector: file_path, *name_path = report.nodeid.split("::") abs_path = str(Path(self.pytest_config.rootdir, file_path)) - test_name, *namespaces = reversed(name_path) + *namespaces, test_name = name_path valid_test_name, *params = test_name.split("[") # ] pos_id = "::".join([abs_path, *namespaces, valid_test_name])