refactoring
This commit is contained in:
parent
d98de31d35
commit
b124625a52
1 changed files with 27 additions and 24 deletions
|
|
@ -33,19 +33,35 @@ class Runner:
|
||||||
assert self.test_dir_name
|
assert self.test_dir_name
|
||||||
self.root_dir = Path(__file__).parent
|
self.root_dir = Path(__file__).parent
|
||||||
|
|
||||||
def _run_main_setup_and_test(self):
|
def run_tests(self):
|
||||||
|
# check if required dependencies have passed
|
||||||
|
self._assert_dependencies_passed()
|
||||||
|
|
||||||
|
# run main setup if available
|
||||||
if isinstance(self.main_setup_name, str):
|
if isinstance(self.main_setup_name, str):
|
||||||
self._run_or_skip_test(
|
self._run_or_skip_test(
|
||||||
identifier_string=self.combine_names(self.name, self.main_setup_name),
|
identifier_string=self.combine_names(self.name, self.main_setup_name),
|
||||||
test_path=self.root_dir / self.test_dir_name / self.main_setup_name,
|
test_path=self.root_dir / self.test_dir_name / self.main_setup_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# run main test if available
|
||||||
if isinstance(self.main_test_name, str):
|
if isinstance(self.main_test_name, str):
|
||||||
self._run_or_skip_test(
|
self._run_or_skip_test(
|
||||||
identifier_string=self.combine_names(self.name, self.main_test_name),
|
identifier_string=self.combine_names(self.name, self.main_test_name),
|
||||||
test_path=self.root_dir / self.test_dir_name / self.main_test_name,
|
test_path=self.root_dir / self.test_dir_name / self.main_test_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# run sub tests if conditions are met
|
||||||
|
for sub_test in self.sub_tests:
|
||||||
|
condition_function = sub_test["condition"]
|
||||||
|
sub_test_name = sub_test["test_file"]
|
||||||
|
identifier_string = self.combine_names(self.name, sub_test_name)
|
||||||
|
if condition_function(self.config):
|
||||||
|
test_path = self.root_dir / self.test_dir_name / sub_test_name
|
||||||
|
self._run_or_skip_test(identifier_string=identifier_string, test_path=test_path)
|
||||||
|
else:
|
||||||
|
self._create_result_file(result=-1, identifier_string=identifier_string)
|
||||||
|
|
||||||
def _run_or_skip_test(self, identifier_string: str, test_path: Path):
|
def _run_or_skip_test(self, identifier_string: str, test_path: Path):
|
||||||
if not self.prevent_skip and self._is_test_passed(identifier_string, remove_existing=True):
|
if not self.prevent_skip and self._is_test_passed(identifier_string, remove_existing=True):
|
||||||
logger.info(f"skipping {identifier_string}")
|
logger.info(f"skipping {identifier_string}")
|
||||||
|
|
@ -116,19 +132,6 @@ class Runner:
|
||||||
|
|
||||||
return pytest.main(command_arguments)
|
return pytest.main(command_arguments)
|
||||||
|
|
||||||
def run_tests(self):
|
|
||||||
self._assert_dependencies_passed()
|
|
||||||
self._run_main_setup_and_test()
|
|
||||||
for sub_test in self.sub_tests:
|
|
||||||
condition_function = sub_test["condition"]
|
|
||||||
sub_test_name = sub_test["test_file"]
|
|
||||||
identifier_string = self.combine_names(self.name, sub_test_name)
|
|
||||||
if condition_function(self.config):
|
|
||||||
test_path = self.root_dir / self.test_dir_name / sub_test_name
|
|
||||||
self._run_or_skip_test(identifier_string=identifier_string, test_path=test_path)
|
|
||||||
else:
|
|
||||||
self._create_result_file(result=-1, identifier_string=identifier_string)
|
|
||||||
|
|
||||||
def _create_result_file(
|
def _create_result_file(
|
||||||
self,
|
self,
|
||||||
result: int,
|
result: int,
|
||||||
|
|
@ -141,6 +144,16 @@ class Runner:
|
||||||
with open(file_path, "w") as _:
|
with open(file_path, "w") as _:
|
||||||
pass # create empty file
|
pass # create empty file
|
||||||
|
|
||||||
|
def _assert_dependencies_passed(self):
|
||||||
|
"""assert that all dependencie setups passed before"""
|
||||||
|
|
||||||
|
passed_tests = [r.name for r in self.DIRS.RESULTS.glob("*") if "passed" in r.name]
|
||||||
|
for dependencie in self.dependencies:
|
||||||
|
dependencie_identifier = self.combine_names(dependencie.name, dependencie.main_setup_name)
|
||||||
|
assert any(
|
||||||
|
dependencie_identifier in f for f in passed_tests
|
||||||
|
), f"could not run {self.name} because {dependencie} did not run before"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def result_int_to_str(result_int: int) -> str:
|
def result_int_to_str(result_int: int) -> str:
|
||||||
match result_int:
|
match result_int:
|
||||||
|
|
@ -154,13 +167,3 @@ class Runner:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def combine_names(*names: str) -> str:
|
def combine_names(*names: str) -> str:
|
||||||
return "-".join(names)
|
return "-".join(names)
|
||||||
|
|
||||||
def _assert_dependencies_passed(self):
|
|
||||||
"""assert that all dependencie setups passed before"""
|
|
||||||
|
|
||||||
passed_tests = [r.name for r in self.DIRS.RESULTS.glob("*") if "passed" in r.name]
|
|
||||||
for dependencie in self.dependencies:
|
|
||||||
dependencie_identifier = self.combine_names(dependencie.name, dependencie.main_setup_name)
|
|
||||||
assert any(
|
|
||||||
dependencie_identifier in f for f in passed_tests
|
|
||||||
), f"could not run {self.name} because {dependencie} did not run before"
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue