add recipes dir to dir manager

This commit is contained in:
Daniel 2023-12-05 18:58:51 +01:00
parent c05f79e36c
commit 52922a5be3
4 changed files with 35 additions and 21 deletions

View file

@ -25,12 +25,10 @@ class Runner:
dependencies: list[str] = []
_dependency_runners: list[type["Runner"]] = []
def __init__(self, dotenv_path: Path, output_dir: Path, session_id: str):
def __init__(self, dotenv_path: Path, DIR: DirManager):
self.dotenv_path = dotenv_path
self.config: dict[str, str] = dotenv_values(dotenv_path) # type: ignore
self.output_dir = output_dir
self.session_id = session_id
self.DIRS = DirManager(output_dir, session_id)
self.DIR = DIR
logger.info(f"creating instance of {self.__class__.__name__}")
assert self.test_dir_name
@ -66,7 +64,7 @@ class Runner:
# condition_met: true / false
identifier_string = self.combine_names(self.name, test.test_file)
test_path = self.root_dir / self.test_dir_name / test.test_file
full_test_path = self.DIR.RECIPES / self.test_dir_name / test.test_file
# check if test aleady passed
if self._is_test_passed(identifier_string, remove_existing=True):
@ -83,7 +81,7 @@ class Runner:
# test condition is undefined or not met
logger.info(f"running {identifier_string}")
result = self._call_pytest(test_path)
result = self._call_pytest(full_test_path)
self._create_result_file(result=result, identifier_string=identifier_string)
def _is_test_passed(self, identifier_string: str, remove_existing: bool = False) -> bool:
@ -96,7 +94,7 @@ class Runner:
other than 'passed' will be deleted"""
already_passed = False
for result in self.DIRS.RESULTS.glob("*"):
for result in self.DIR.RESULTS.glob("*"):
if identifier_string in result.name:
# process any result file (passed / failed / skipped) if it exists
if "passed" in result.name:
@ -112,6 +110,8 @@ class Runner:
command_arguments = []
# command_arguments.append("--traceconfig")
command_arguments.append("-v")
# command_arguments.append("-rx")
command_arguments.append(str(full_test_path))
@ -121,17 +121,17 @@ class Runner:
# set root dir for tests output (used in DirManager). this is our custom argument
command_arguments.append("--output_dir")
command_arguments.append(str(self.DIRS.OUTPUT_DIR))
command_arguments.append(str(self.DIR.OUTPUT_DIR))
command_arguments.append("--session_id")
command_arguments.append(self.session_id)
command_arguments.append(self.DIR.session_id)
# artifacts dir from pytest
# warning: https://github.com/microsoft/playwright-pytest/issues/111
# --output only works with the given context and page fixture
# folder needs to be unique! traces will not appear, if every pytest run has same output dir
command_arguments.append("--output")
command_arguments.append(str(self.DIRS.RECORDS / "traces" / full_test_path.stem))
command_arguments.append(str(self.DIR.RECORDS / "traces" / full_test_path.stem))
# tracing
command_arguments.append("--tracing")
@ -145,7 +145,7 @@ class Runner:
# command_arguments.append("--headed")
# html report. Will be combined into one file later.
command_arguments.append(f"--html={self.DIRS.RECORDS / 'html' / full_test_path.with_suffix('.html').name}")
command_arguments.append(f"--html={self.DIR.RECORDS / 'html' / full_test_path.with_suffix('.html').name}")
return pytest.main(command_arguments)
@ -157,7 +157,7 @@ class Runner:
"""create result file to indicated passed/failed or skipped test"""
full_name = self.combine_names(self.result_int_to_str(result), identifier_string)
file_path = self.DIRS.RESULTS / full_name
file_path = self.DIR.RESULTS / full_name
with open(file_path, "w") as _:
pass # create empty file
@ -166,7 +166,7 @@ class Runner:
# todo: what about conditional setups?
passed_tests = [r.name for r in self.DIRS.RESULTS.glob("*") if "passed" in r.name]
passed_tests = [r.name for r in self.DIR.RESULTS.glob("*") if "passed" in r.name]
results = []
for dependency_runner in self._dependency_runners:
for setup_name in dependency_runner.setups: