everything working
This commit is contained in:
parent
3fe9ed28db
commit
224ad2ea85
2 changed files with 47 additions and 45 deletions
45
src/runner.py
Normal file
45
src/runner.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
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):
|
||||||
|
assert self.test_dir_name is not None
|
||||||
|
self.root_dir = Path(__file__).parent
|
||||||
|
self.dotenv_path = dotenv_path
|
||||||
|
|
||||||
|
def _run_main_test(self):
|
||||||
|
if isinstance(self.main_test_name, str):
|
||||||
|
self._run_pytest(self.main_test_name)
|
||||||
|
|
||||||
|
def _run_pytest(self, test_name: str):
|
||||||
|
pytest.main(
|
||||||
|
[
|
||||||
|
self.root_dir / self.test_dir_name / test_name,
|
||||||
|
"--env_file_path",
|
||||||
|
self.dotenv_path,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
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"]
|
||||||
|
self._run_pytest(test_name)
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Optional, TypedDict
|
|
||||||
|
|
||||||
import pytest
|
from runner import Runner, SubTest
|
||||||
from dotenv import dotenv_values
|
|
||||||
from icecream import ic
|
|
||||||
|
|
||||||
|
|
||||||
class SubTest(TypedDict):
|
|
||||||
condition: Callable[[Path], bool]
|
|
||||||
test_file: str
|
|
||||||
|
|
||||||
|
|
||||||
def condition_feature1(dotenv_path: Path) -> bool:
|
def condition_feature1(dotenv_path: Path) -> bool:
|
||||||
|
|
@ -19,43 +11,8 @@ def condition_always_true(dotenv_path: Path) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Runner:
|
|
||||||
test_dir: Optional[str] = None
|
|
||||||
main_test_name: Optional[str] = None
|
|
||||||
sub_tests: list[SubTest] = []
|
|
||||||
|
|
||||||
def __init__(self, dotenv_path: Path):
|
|
||||||
assert self.test_dir is not None
|
|
||||||
self.dotenv_path = dotenv_path
|
|
||||||
# self.root_dir = self.dotenv_path.parent
|
|
||||||
|
|
||||||
def _run_main_test(self):
|
|
||||||
if isinstance(self.main_test_name, str):
|
|
||||||
self._run_pytest(self.main_test_name)
|
|
||||||
|
|
||||||
def _run_pytest(self, test_name: str):
|
|
||||||
pytest.main(
|
|
||||||
[
|
|
||||||
self.root_dir / self.test_dir / test_name,
|
|
||||||
"--env_file_path",
|
|
||||||
self.dotenv_path,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
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():
|
|
||||||
test_name = sub_test["test_file"]
|
|
||||||
self._run_pytest(test_name)
|
|
||||||
|
|
||||||
|
|
||||||
class RunnerWordpress(Runner):
|
class RunnerWordpress(Runner):
|
||||||
test_dir = "tests_wordpress"
|
test_dir_name = "tests_wordpress"
|
||||||
main_test_name = "test_wordpress.py"
|
main_test_name = "test_wordpress.py"
|
||||||
sub_tests = [
|
sub_tests = [
|
||||||
SubTest(condition=condition_always_true, test_file="test_wordpress_feature1.py")
|
SubTest(condition=condition_always_true, test_file="test_wordpress_feature1.py")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue