installable package (#9)
* turn repo into installable package (pip install -e .) * add hatchling build packend * call it pytest-abra * add pytest entrypoint, so that it gets loaded automatically if installed (and pytest is run) * make fixtures optional, so that pytest can still be used in other context * add cli script -> you can now directly run "pytest-abra" in console Reviewed-on: local-it-infrastructure/e2e_tests#9 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
4c5a470a70
commit
8685688698
33 changed files with 294 additions and 210 deletions
78
pytest_abra/dir_manager.py
Normal file
78
pytest_abra/dir_manager.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
from pathlib import Path
|
||||
|
||||
from dotenv import dotenv_values
|
||||
|
||||
|
||||
class DirManager:
|
||||
"""Manages directories for the tests and should be used to create and find
|
||||
and use the correct directories.
|
||||
|
||||
The structures is as follows:
|
||||
tests dir/
|
||||
session_dir-1/
|
||||
records
|
||||
results
|
||||
states
|
||||
session_dir-2/
|
||||
records
|
||||
...
|
||||
"""
|
||||
|
||||
def __init__(self, output_dir: Path | str, session_id: str, recipes_dir: Path | str = ""):
|
||||
if isinstance(output_dir, str):
|
||||
output_dir = Path(output_dir)
|
||||
self.output_dir = output_dir.resolve()
|
||||
self.session_id = session_id
|
||||
if isinstance(recipes_dir, str):
|
||||
recipes_dir = Path(recipes_dir)
|
||||
self.recipes_dir = recipes_dir
|
||||
|
||||
def create_all_dirs(self) -> None:
|
||||
dirs: list[Path] = [
|
||||
self.OUTPUT_DIR,
|
||||
self.SESSION,
|
||||
self.RECORDS,
|
||||
self.HTML,
|
||||
self.STATES,
|
||||
self.ENV_FILES,
|
||||
self.RESULTS,
|
||||
]
|
||||
for d in dirs:
|
||||
d.mkdir(exist_ok=True)
|
||||
|
||||
@property
|
||||
def OUTPUT_DIR(self):
|
||||
return self.output_dir
|
||||
|
||||
@property
|
||||
def SESSION(self):
|
||||
return self.OUTPUT_DIR / self.session_id
|
||||
|
||||
@property
|
||||
def RECORDS(self):
|
||||
return self.SESSION / "records"
|
||||
|
||||
@property
|
||||
def HTML(self):
|
||||
return self.RECORDS / "html"
|
||||
|
||||
@property
|
||||
def STATES(self):
|
||||
return self.SESSION / "states"
|
||||
|
||||
@property
|
||||
def ENV_FILES(self):
|
||||
return self.STATES / "env_files"
|
||||
|
||||
@property
|
||||
def RESULTS(self):
|
||||
return self.SESSION / "results"
|
||||
|
||||
@property
|
||||
def RECIPES(self):
|
||||
return self.recipes_dir
|
||||
|
||||
def get_config(self, search_string: str) -> dict[str, str]:
|
||||
env_file = next(self.ENV_FILES.glob(f"*{search_string}*"))
|
||||
config: dict[str, str] = dotenv_values(env_file) # type: ignore
|
||||
return config
|
||||
Loading…
Add table
Add a link
Reference in a new issue