use new pytest command args in Runner

This commit is contained in:
Daniel 2023-11-22 14:33:51 +01:00
parent 8f827d7f7b
commit 5ce20f0b81

View file

@ -15,25 +15,36 @@ class Runner:
main_test_name: Optional[str] = None
sub_tests: list[SubTest] = []
def __init__(self, dotenv_path: Path):
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
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):
ic(f"running test: {test_name}")
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",
self.root_dir / self.test_dir_name / test_name,
"--env_file_path",
self.dotenv_path,
str(full_test_path),
"--env_file",
str(self.dotenv_path),
"--tests_dir",
str(self.tests_dir),
"--session_id",
self.session_id,
]
)
@ -46,4 +57,5 @@ class Runner:
condition_function = sub_test["condition"]
if condition_function(self.dotenv_path):
test_name = sub_test["test_file"]
self._run_pytest(test_name)
full_test_path = self.root_dir / self.test_dir_name / test_name
self._run_pytest(full_test_path)