add recipes dir to dir manager
This commit is contained in:
parent
c05f79e36c
commit
52922a5be3
4 changed files with 35 additions and 21 deletions
12
main.py
12
main.py
|
|
@ -8,6 +8,13 @@ from src.coordinator import Coordinator
|
||||||
from src.dir_manager import DirManager
|
from src.dir_manager import DirManager
|
||||||
from src.utils import get_session_id
|
from src.utils import get_session_id
|
||||||
|
|
||||||
|
# --------------------------- set all env variables -------------------------- #
|
||||||
|
|
||||||
|
|
||||||
|
# add abra-testing dir
|
||||||
|
os.environ["PYTEST_PLUGINS"] = "src.plugin-abra" # "src.plugin,src.other"
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------- lookup env files ----------------------------- #
|
# ----------------------------- lookup env files ----------------------------- #
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,6 +38,7 @@ ENV_FILES = [
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_DIR = Path("./test-output").resolve()
|
OUTPUT_DIR = Path("./test-output").resolve()
|
||||||
|
RECIPES_DIR = Path("./src-tests").resolve()
|
||||||
|
|
||||||
|
|
||||||
# -------------------------- enable playwright debug ------------------------- #
|
# -------------------------- enable playwright debug ------------------------- #
|
||||||
|
|
@ -67,7 +75,9 @@ logger.add(log_file)
|
||||||
# ---------------------------- initialize and run ---------------------------- #
|
# ---------------------------- initialize and run ---------------------------- #
|
||||||
|
|
||||||
|
|
||||||
coordinator = Coordinator(ENV_FILES, output_dir=OUTPUT_DIR, session_id=session_id)
|
coordinator = Coordinator(
|
||||||
|
env_paths_list=ENV_FILES, output_dir=OUTPUT_DIR, session_id=session_id, recipes_dir=RECIPES_DIR
|
||||||
|
)
|
||||||
coordinator.setup_test()
|
coordinator.setup_test()
|
||||||
coordinator.run_test()
|
coordinator.run_test()
|
||||||
coordinator.combine_html()
|
coordinator.combine_html()
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ from src.utils import rmtree
|
||||||
|
|
||||||
|
|
||||||
class Coordinator:
|
class Coordinator:
|
||||||
def __init__(self, env_paths_list: list[Path], output_dir: Path, session_id: str) -> None:
|
def __init__(self, env_paths_list: list[Path], output_dir: Path, session_id: str, recipes_dir: Path) -> None:
|
||||||
# logging
|
# logging
|
||||||
out_string = "".join([e.name + "\n" for e in env_paths_list])
|
out_string = "".join([e.name + "\n" for e in env_paths_list])
|
||||||
out_string += f"output_dir = {output_dir}\n"
|
out_string += f"output_dir = {output_dir}\n"
|
||||||
out_string += f"session_id = {session_id}"
|
out_string += f"session_id = {session_id}"
|
||||||
logger.info(f"initialize Coordinator instance with\nenv_paths_list =\n{out_string}")
|
logger.info(f"initialize Coordinator instance with\nenv_paths_list =\n{out_string}")
|
||||||
|
|
||||||
self.DIR = DirManager(output_dir=output_dir, session_id=session_id)
|
self.DIR = DirManager(output_dir=output_dir, session_id=session_id, recipes_dir=recipes_dir)
|
||||||
self.ENV = EnvManager(env_paths_list)
|
self.ENV = EnvManager(env_paths_list)
|
||||||
|
|
||||||
def setup_test(self) -> None:
|
def setup_test(self) -> None:
|
||||||
|
|
@ -45,9 +45,7 @@ class Coordinator:
|
||||||
dependency_classes: list[type[Runner]] = []
|
dependency_classes: list[type[Runner]] = []
|
||||||
for dependency in RunnerClass.dependencies:
|
for dependency in RunnerClass.dependencies:
|
||||||
dependency_classes.append(RUNNER_DICT[dependency])
|
dependency_classes.append(RUNNER_DICT[dependency])
|
||||||
runner_instance = RunnerClass(
|
runner_instance = RunnerClass(dotenv_path=env_file.env_path, DIR=self.DIR)
|
||||||
dotenv_path=env_file.env_path, output_dir=self.DIR.output_dir, session_id=self.DIR.session_id
|
|
||||||
)
|
|
||||||
runner_instance._dependency_runners = dependency_classes
|
runner_instance._dependency_runners = dependency_classes
|
||||||
runners.append(runner_instance)
|
runners.append(runner_instance)
|
||||||
return runners
|
return runners
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,14 @@ class DirManager:
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, output_dir: Path | str, session_id: str):
|
def __init__(self, output_dir: Path | str, session_id: str, recipes_dir: Path | str = ""):
|
||||||
# root test dir
|
|
||||||
if isinstance(output_dir, str):
|
if isinstance(output_dir, str):
|
||||||
output_dir = Path(output_dir)
|
output_dir = Path(output_dir)
|
||||||
self.output_dir = output_dir.resolve()
|
self.output_dir = output_dir.resolve()
|
||||||
self.session_id = session_id
|
self.session_id = session_id
|
||||||
|
if isinstance(recipes_dir, str):
|
||||||
|
recipes_dir = Path(recipes_dir)
|
||||||
|
self.recipes_dir = recipes_dir
|
||||||
|
|
||||||
def create_all_dirs(self) -> None:
|
def create_all_dirs(self) -> None:
|
||||||
dirs: list[Path] = [
|
dirs: list[Path] = [
|
||||||
|
|
@ -63,3 +65,7 @@ class DirManager:
|
||||||
@property
|
@property
|
||||||
def RESULTS(self):
|
def RESULTS(self):
|
||||||
return self.SESSION / "results"
|
return self.SESSION / "results"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def RECIPES(self):
|
||||||
|
return self.recipes_dir
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,10 @@ class Runner:
|
||||||
dependencies: list[str] = []
|
dependencies: list[str] = []
|
||||||
_dependency_runners: list[type["Runner"]] = []
|
_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.dotenv_path = dotenv_path
|
||||||
self.config: dict[str, str] = dotenv_values(dotenv_path) # type: ignore
|
self.config: dict[str, str] = dotenv_values(dotenv_path) # type: ignore
|
||||||
self.output_dir = output_dir
|
self.DIR = DIR
|
||||||
self.session_id = session_id
|
|
||||||
self.DIRS = DirManager(output_dir, session_id)
|
|
||||||
|
|
||||||
logger.info(f"creating instance of {self.__class__.__name__}")
|
logger.info(f"creating instance of {self.__class__.__name__}")
|
||||||
assert self.test_dir_name
|
assert self.test_dir_name
|
||||||
|
|
@ -66,7 +64,7 @@ class Runner:
|
||||||
# condition_met: true / false
|
# condition_met: true / false
|
||||||
|
|
||||||
identifier_string = self.combine_names(self.name, test.test_file)
|
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
|
# check if test aleady passed
|
||||||
if self._is_test_passed(identifier_string, remove_existing=True):
|
if self._is_test_passed(identifier_string, remove_existing=True):
|
||||||
|
|
@ -83,7 +81,7 @@ class Runner:
|
||||||
|
|
||||||
# test condition is undefined or not met
|
# test condition is undefined or not met
|
||||||
logger.info(f"running {identifier_string}")
|
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)
|
self._create_result_file(result=result, identifier_string=identifier_string)
|
||||||
|
|
||||||
def _is_test_passed(self, identifier_string: str, remove_existing: bool = False) -> bool:
|
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"""
|
other than 'passed' will be deleted"""
|
||||||
|
|
||||||
already_passed = False
|
already_passed = False
|
||||||
for result in self.DIRS.RESULTS.glob("*"):
|
for result in self.DIR.RESULTS.glob("*"):
|
||||||
if identifier_string in result.name:
|
if identifier_string in result.name:
|
||||||
# process any result file (passed / failed / skipped) if it exists
|
# process any result file (passed / failed / skipped) if it exists
|
||||||
if "passed" in result.name:
|
if "passed" in result.name:
|
||||||
|
|
@ -112,6 +110,8 @@ class Runner:
|
||||||
|
|
||||||
command_arguments = []
|
command_arguments = []
|
||||||
|
|
||||||
|
# command_arguments.append("--traceconfig")
|
||||||
|
|
||||||
command_arguments.append("-v")
|
command_arguments.append("-v")
|
||||||
# command_arguments.append("-rx")
|
# command_arguments.append("-rx")
|
||||||
command_arguments.append(str(full_test_path))
|
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
|
# set root dir for tests output (used in DirManager). this is our custom argument
|
||||||
command_arguments.append("--output_dir")
|
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("--session_id")
|
||||||
command_arguments.append(self.session_id)
|
command_arguments.append(self.DIR.session_id)
|
||||||
|
|
||||||
# artifacts dir from pytest
|
# artifacts dir from pytest
|
||||||
# warning: https://github.com/microsoft/playwright-pytest/issues/111
|
# warning: https://github.com/microsoft/playwright-pytest/issues/111
|
||||||
# --output only works with the given context and page fixture
|
# --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
|
# folder needs to be unique! traces will not appear, if every pytest run has same output dir
|
||||||
command_arguments.append("--output")
|
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
|
# tracing
|
||||||
command_arguments.append("--tracing")
|
command_arguments.append("--tracing")
|
||||||
|
|
@ -145,7 +145,7 @@ class Runner:
|
||||||
# command_arguments.append("--headed")
|
# command_arguments.append("--headed")
|
||||||
|
|
||||||
# html report. Will be combined into one file later.
|
# 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)
|
return pytest.main(command_arguments)
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ class Runner:
|
||||||
"""create result file to indicated passed/failed or skipped test"""
|
"""create result file to indicated passed/failed or skipped test"""
|
||||||
|
|
||||||
full_name = self.combine_names(self.result_int_to_str(result), identifier_string)
|
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 _:
|
with open(file_path, "w") as _:
|
||||||
pass # create empty file
|
pass # create empty file
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ class Runner:
|
||||||
|
|
||||||
# todo: what about conditional setups?
|
# 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 = []
|
results = []
|
||||||
for dependency_runner in self._dependency_runners:
|
for dependency_runner in self._dependency_runners:
|
||||||
for setup_name in dependency_runner.setups:
|
for setup_name in dependency_runner.setups:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue