refactor so that coordinator instance is available in runner instance (#8)
-> all program states available Reviewed-on: local-it-infrastructure/e2e_tests#8 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
f9c21c6e6b
commit
4c5a470a70
15 changed files with 74 additions and 53 deletions
|
|
@ -1,12 +1,13 @@
|
|||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
|
||||
import pytest
|
||||
from dotenv import dotenv_values
|
||||
from loguru import logger
|
||||
|
||||
from abratest.dir_manager import DirManager
|
||||
if TYPE_CHECKING:
|
||||
from abratest.coordinator import Coordinator
|
||||
from abratest.env_manager import EnvFile
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -17,22 +18,25 @@ class Test:
|
|||
|
||||
|
||||
class Runner:
|
||||
name: str = ""
|
||||
test_dir_name: str = ""
|
||||
env_type: str = ""
|
||||
setups: list[Test] = []
|
||||
tests: list[Test] = []
|
||||
cleanups: list[Test] = []
|
||||
dependencies: list[str] = []
|
||||
_dependency_runners: list[type["Runner"]] = []
|
||||
|
||||
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.DIR = DIR
|
||||
def __init__(self, coordinator: "Coordinator", runner_index: int):
|
||||
self.coordinator = coordinator # needed?
|
||||
self.runner_index = runner_index # needed?
|
||||
|
||||
self.DIR = coordinator.DIR
|
||||
self.ENV = coordinator.ENV
|
||||
self.RUNNER_DICT = coordinator.RUNNER_DICT
|
||||
|
||||
self.env_file: EnvFile = self.ENV.env_files[self.runner_index]
|
||||
self.dotenv_path = self.env_file.env_path
|
||||
self.config = self.env_file.config
|
||||
|
||||
logger.info(f"creating instance of {self.__class__.__name__}")
|
||||
assert self.test_dir_name
|
||||
self.root_dir = Path(__file__).parent
|
||||
|
||||
def run_setups(self):
|
||||
"""runs the setup scripts if available"""
|
||||
|
|
@ -50,7 +54,7 @@ class Runner:
|
|||
"""runs the main test script and if available and sub test scripts if their running condition is met"""
|
||||
# check if required dependencies have passed
|
||||
if not self._dependencies_passed():
|
||||
logger.warning(f"skipping run_tests() of {self.name}, because some dependencies have not passed")
|
||||
logger.warning(f"skipping run_tests() of {self.env_type}, because some dependencies have not passed")
|
||||
return
|
||||
|
||||
for test in test_list:
|
||||
|
|
@ -63,8 +67,11 @@ class Runner:
|
|||
# condition_available: true / pass
|
||||
# condition_met: true / false
|
||||
|
||||
identifier_string = self.combine_names(self.name, test.test_file)
|
||||
full_test_path = self.DIR.RECIPES / self.name / self.test_dir_name / test.test_file
|
||||
identifier_string = self.combine_names(self.env_type, test.test_file)
|
||||
|
||||
results = list(self.DIR.RECIPES.rglob(test.test_file))
|
||||
assert len(results) == 1, f"{test.test_file} should exist exactly 1 time, but found {len(results)} times"
|
||||
full_test_path = results[0]
|
||||
|
||||
# check if test aleady passed
|
||||
if self._is_test_passed(identifier_string, remove_existing=True):
|
||||
|
|
@ -168,9 +175,10 @@ class Runner:
|
|||
|
||||
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 dependency in self.dependencies:
|
||||
dependency_runner = self.coordinator.RUNNER_DICT[dependency]
|
||||
for setup_name in dependency_runner.setups:
|
||||
dependencie_identifier = self.combine_names(dependency_runner.name, setup_name.test_file)
|
||||
dependencie_identifier = self.combine_names(dependency_runner.env_type, setup_name.test_file)
|
||||
results.append(any(dependencie_identifier in f for f in passed_tests))
|
||||
return all(results)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue