diff --git a/pytest_launchable/conftest.py b/pytest_launchable/conftest.py index a740542..0c2b86b 100755 --- a/pytest_launchable/conftest.py +++ b/pytest_launchable/conftest.py @@ -4,7 +4,6 @@ from typing import List, Optional, Tuple, Union import pytest -from .memorizer import memorizer from launchable_cli_args import CLIArgs from lxml.builder import E # type: ignore from lxml import etree # type: ignore @@ -15,6 +14,10 @@ TestNameList = Tuple[Optional[str], str, Optional[str]] +testpath_re = re.compile( + "file=(?P([^#]+))(#class=(?P([^#]+)))?#testcase=(?P(.+))$") +pytest_test_file_re = re.compile(".*test_.*\.py$") + class LaunchableTestContext: def __init__(self): @@ -32,15 +35,16 @@ def get_node_from_path(self, path: str) -> "LaunchableTestNode": self.test_node_list.append(node) return node - def find_testcase_from_testpath(self, testpath: str) -> "LaunchableTestCase": - @memorizer - def testpath_re(): - return re.compile("file=(?P([^#]+))(#class=(?P([^#]+)))?#testcase=(?P(.+))$") - m = testpath_re().match(testpath) + def find_testcase_from_testpath(self, testpath: str) -> Optional["LaunchableTestCase"]: + m = testpath_re.match(testpath) + if m is None: + return None + e = m.groupdict() + class_name = e.get("class") # class is optional - return self.get_node_from_path(e["file"]).find_test_case(e.get("class"), e["testcase"]) + return self.get_node_from_path(e["file"]).find_test_case(class_name, e["testcase"]) def set_subset_command_request(self, command, input_files: List[str]) -> None: self.subset_command = command @@ -98,7 +102,7 @@ def add_test_case(self, pytest_item: pytest.Function, test_name_tuple: TestNameL def short_str(self): return ",".join(map(lambda c: c.short_str(), self.case_list)) - def find_test_case(self, class_name: str, function_name_and_parameters: str): + def find_test_case(self, class_name: Optional[str], function_name_and_parameters: str) -> Optional["LaunchableTestCase"]: for testcase in self.case_list: if testcase.class_name == class_name and testcase.function_name_and_parameters == function_name_and_parameters: return testcase @@ -198,10 +202,7 @@ def collect_junit_element(self, array: List) -> None: def is_pytest_test_file(path: str) -> bool: """check the path is pytest test file or not""" - @memorizer - def pytest_test_file_re(): - return re.compile(".*test_.*\.py$") - return pytest_test_file_re().match(path) + return pytest_test_file_re.match(path) is not None def read_test_path_list_file(filename: str) -> List[str]: diff --git a/pytest_launchable/memorizer.py b/pytest_launchable/memorizer.py deleted file mode 100644 index 85fb3ba..0000000 --- a/pytest_launchable/memorizer.py +++ /dev/null @@ -1,16 +0,0 @@ -# cache the result of function call -# note that arguments are passed as is. - -# The new version python seems to have similar features, we will support the old python as well. - -def memorizer(f): - func_to_value = {} - - def w(*args): - if f in func_to_value: # cache hit - return func_to_value[f] - else: - v = f(*args) - func_to_value[f] = v - return v - return w diff --git a/tests/test_memorizer.py b/tests/test_memorizer.py deleted file mode 100644 index 4fc73df..0000000 --- a/tests/test_memorizer.py +++ /dev/null @@ -1,16 +0,0 @@ -from pytest_launchable.memorizer import memorizer - - -class Test_Memorizer: - @memorizer - def body(self): - self.call_count += 1 - return 100 - - def test_memorize(self): - self.call_count = 0 - a = self.body() - b = self.body() - assert a == 100 - assert b == 100 - assert self.call_count == 1, "must evaluate only once"