Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
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
25 changes: 13 additions & 12 deletions pytest_launchable/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +14,10 @@

TestNameList = Tuple[Optional[str], str, Optional[str]]

testpath_re = re.compile(
"file=(?P<file>([^#]+))(#class=(?P<class>([^#]+)))?#testcase=(?P<testcase>(.+))$")
pytest_test_file_re = re.compile(".*test_.*\.py$")


class LaunchableTestContext:
def __init__(self):
Expand All @@ -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<file>([^#]+))(#class=(?P<class>([^#]+)))?#testcase=(?P<testcase>(.+))$")
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
16 changes: 0 additions & 16 deletions pytest_launchable/memorizer.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/test_memorizer.py

This file was deleted.