[WIP] Add new automated test framework (#1)
Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
859bd57006
commit
97ed87c79f
31 changed files with 769 additions and 6 deletions
62
src/runner.py
Normal file
62
src/runner.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
from pathlib import Path
|
||||
from typing import Callable, Optional, TypedDict
|
||||
|
||||
import pytest
|
||||
from icecream import ic
|
||||
|
||||
|
||||
class SubTest(TypedDict):
|
||||
condition: Callable[[Path], bool]
|
||||
test_file: str
|
||||
|
||||
|
||||
class Runner:
|
||||
test_dir_name: Optional[Path] = None
|
||||
main_test_name: Optional[str] = None
|
||||
sub_tests: list[SubTest] = []
|
||||
|
||||
def __init__(self, dotenv_path: Path, tests_dir: Path, session_id: str):
|
||||
self.dotenv_path = dotenv_path
|
||||
self.tests_dir = tests_dir
|
||||
self.session_id = session_id
|
||||
|
||||
ic(f"creating instance of {self.__class__.__name__}")
|
||||
assert self.test_dir_name is not None
|
||||
self.root_dir = Path(__file__).parent
|
||||
|
||||
def _run_main_test(self):
|
||||
if isinstance(self.main_test_name, str):
|
||||
full_test_path = self.root_dir / self.test_dir_name / self.main_test_name
|
||||
self._run_pytest(full_test_path)
|
||||
|
||||
def _run_pytest(self, full_test_path: Path):
|
||||
"""runs pytest programmatically
|
||||
|
||||
will run all tests in the file at full_test_path with some command line arguments"""
|
||||
|
||||
ic(f"running test: {full_test_path}")
|
||||
pytest.main(
|
||||
[
|
||||
"-v",
|
||||
"-rp",
|
||||
str(full_test_path),
|
||||
"--env_file",
|
||||
str(self.dotenv_path),
|
||||
"--tests_dir",
|
||||
str(self.tests_dir),
|
||||
"--session_id",
|
||||
self.session_id,
|
||||
]
|
||||
)
|
||||
|
||||
def show_files(self):
|
||||
ic(list(self.root_dir.glob("*")))
|
||||
|
||||
def run_tests(self):
|
||||
self._run_main_test()
|
||||
for sub_test in self.sub_tests:
|
||||
condition_function = sub_test["condition"]
|
||||
if condition_function(self.dotenv_path):
|
||||
test_name = sub_test["test_file"]
|
||||
full_test_path = self.root_dir / self.test_dir_name / test_name
|
||||
self._run_pytest(full_test_path)
|
||||
Loading…
Add table
Add a link
Reference in a new issue