refactoring (#13)
* general project refactoring * various small improvements * improve imap fixture with helper functions and typing * add wordpress send email setup * add wordpress receive email test * add various documentation Reviewed-on: local-it-infrastructure/e2e_tests#13 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
41a042f07d
commit
d1ff1183a5
29 changed files with 323 additions and 175 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
from typing import TYPE_CHECKING, Callable, NamedTuple
|
||||
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
|
@ -10,10 +10,16 @@ if TYPE_CHECKING:
|
|||
from pytest_abra.env_manager import EnvFile
|
||||
|
||||
|
||||
class ConditionArgs(NamedTuple):
|
||||
env_config: dict[str, str]
|
||||
runner_index: int
|
||||
env_files: list["EnvFile"]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Test:
|
||||
test_file: str
|
||||
condition: Callable[[dict[str, str]], bool] | None = None
|
||||
condition: Callable[[ConditionArgs], bool] | None = None
|
||||
prevent_skip: bool = False
|
||||
|
||||
|
||||
|
|
@ -25,17 +31,13 @@ class Runner:
|
|||
dependencies: list[str] = []
|
||||
|
||||
def __init__(self, coordinator: "Coordinator", runner_index: int):
|
||||
self.coordinator = coordinator # needed?
|
||||
self.runner_index = runner_index # needed?
|
||||
self.coordinator = coordinator
|
||||
self.runner_index = runner_index
|
||||
|
||||
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__}")
|
||||
|
||||
def run_setups(self):
|
||||
|
|
@ -81,16 +83,28 @@ class Runner:
|
|||
logger.info(f"skipping {identifier_string}, test has passed")
|
||||
return
|
||||
|
||||
if test.condition and not test.condition(self.config):
|
||||
# test condition is defined but not met
|
||||
logger.info(f"skipping {identifier_string}, test condition is not met")
|
||||
return
|
||||
if test.condition:
|
||||
condition_result = self._run_condition(test.condition)
|
||||
if not condition_result:
|
||||
# test condition is defined but not met
|
||||
logger.info(f"skipping {identifier_string}, test condition is not met")
|
||||
return
|
||||
|
||||
# test condition is undefined or not met
|
||||
logger.info(f"running {identifier_string}")
|
||||
result = self._call_pytest(full_test_path)
|
||||
self._create_result_file(result=result, identifier_string=identifier_string)
|
||||
|
||||
def _run_condition(self, condition_function: Callable[[ConditionArgs], bool]):
|
||||
"""run the test condition function with multiple arguments"""
|
||||
# more arguments can be added later without changing the function signature
|
||||
conditon_args = ConditionArgs(
|
||||
env_files=self.ENV.env_files,
|
||||
runner_index=self.runner_index,
|
||||
env_config=self.ENV.env_files[self.runner_index].env_config,
|
||||
)
|
||||
return condition_function(conditon_args)
|
||||
|
||||
def _is_test_passed(self, identifier_string: str, remove_existing: bool = False) -> bool:
|
||||
"""returns True if the selected test matching identifier_string already passed
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue