From 6c06041cfb45f45e276068020baa06c06fe20d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Sat, 18 Feb 2023 09:34:37 +0000 Subject: [PATCH] fix(unittest): correct arg order for test vs suite See #45 --- neotest_python/unittest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neotest_python/unittest.py b/neotest_python/unittest.py index b1901a9..856ee08 100644 --- a/neotest_python/unittest.py +++ b/neotest_python/unittest.py @@ -26,7 +26,7 @@ class UnittestNeotestAdapter(NeotestAdapter): def case_id(self, case: "TestCase | TestSuite") -> str: return "::".join(self.case_id_elems(case)) - def id_to_unittest_args(self, case_id: str) -> List[str]: + def convert_args(self, case_id: str, args: List[str]) -> List[str]: """Converts a neotest ID into test specifier for unittest""" path, *child_ids = case_id.split("::") if not child_ids: @@ -34,13 +34,13 @@ class UnittestNeotestAdapter(NeotestAdapter): # Test files can be passed directly to unittest return [path] # Directories need to be run via the 'discover' argument - return ["discover", "-s", path] + return ["discover", "-s", path, *args] # Otherwise, convert the ID into a dotted path, relative to current dir relative_file = os.path.relpath(path, os.getcwd()) relative_stem = os.path.splitext(relative_file)[0] relative_dotted = relative_stem.replace(os.sep, ".") - return [".".join([relative_dotted, *child_ids])] + return [*args, ".".join([relative_dotted, *child_ids])] # TODO: Stream results def run(self, args: List[str], _) -> Dict: @@ -93,7 +93,7 @@ class UnittestNeotestAdapter(NeotestAdapter): sys.path.insert(0, os.getcwd()) # Prepend an executable name which is just used in output - argv = ["neotest-python"] + self.id_to_unittest_args(args[-1]) + args[:-1] + argv = ["neotest-python"] + self.convert_args(args[-1], args[:-1]) unittest.main( module=None, argv=argv,