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:
Daniel 2023-12-07 11:32:01 +01:00 committed by dan
parent 4c5a470a70
commit 8685688698
33 changed files with 294 additions and 210 deletions

92
main.py
View file

@ -1,42 +1,10 @@
import json
import os
import subprocess
from pathlib import Path
from loguru import logger
from abratest.coordinator import Coordinator
from abratest.dir_manager import DirManager
from abratest.utils import get_session_id
# ----------------------------- lookup env files ----------------------------- #
# This list of env files is the input to testing framework. each env file
# triggers the execution of one test Runner and provides configuration to the
# tests inside the runner. There can be dependencies, for example wordpress
# requires that authentik ran first to create the admin session and the user
# session. At the moment, wrong ordering results in unsuccessful test
# (wrong ordering would be wordpress env file is before authentik env file).
# At the moment, functionailty is only guaranteed if each env file use
# a unique TYPE var.
ENV_FILES = [
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
# Path("envfiles/files.test.dev.local-it.cloud.env"), # nextcloud
]
# ----------------------------- define ouptut dir ---------------------------- #
OUTPUT_DIR = Path("./test-output").resolve()
RECIPES_DIR = Path("./recipes").resolve()
# --------------------- load credentials to env variables -------------------- #
cred_file = Path("credentials.json")
with open(cred_file, "r") as f:
CREDENTIALS = json.load(f)
@ -44,37 +12,35 @@ with open(cred_file, "r") as f:
for key, value in CREDENTIALS.items():
os.environ[key] = value
# --------------------------------- env files -------------------------------- #
# -------------------------- enable playwright debug ------------------------- #
# This list of env files is the input to testing framework. each env file
# triggers the execution of one test Runner and provides configuration to the
# tests inside the runner.
ENV_FILES_ROOT = Path("../envfiles").resolve()
ENV_FILES = [
ENV_FILES_ROOT / "login.test.dev.local-it.cloud.env", # authentik
ENV_FILES_ROOT / "blog.test.dev.local-it.cloud.env", # wordpress
ENV_FILES_ROOT / "files.test.dev.local-it.cloud.env", # nextcloud
]
ENV_PATHS = ";".join([x.as_posix() for x in ENV_FILES])
# ----------------------------------- dirs ----------------------------------- #
RECIPES_DIR = Path("../recipes").resolve()
OUTPUT_DIR = Path("./test-output").resolve()
# add abra-testing dir
os.environ["PYTEST_PLUGINS"] = "abratest.plugin-abra" # "abratest.plugin,abratest.other"
# os.environ["PWDEBUG"] = "1"
# ----------------------------- define session_id ---------------------------- #
session_id = get_session_id()
# session_id = "abc"
# ------------------------------- setup logging ------------------------------ #
DIR = DirManager(output_dir=OUTPUT_DIR, session_id=session_id)
log_file = DIR.RECORDS / "coordinator.log"
logger.add(log_file)
# ---------------------------- initialize and run ---------------------------- #
coordinator = Coordinator(
env_paths_list=ENV_FILES, output_dir=OUTPUT_DIR, session_id=session_id, recipes_dir=RECIPES_DIR
subprocess.run(
[
"abratest",
"--env_paths",
ENV_PATHS,
"--recipes_dir",
RECIPES_DIR,
"--output_dir",
OUTPUT_DIR,
# "--debug",
]
)
coordinator.setup_test()
coordinator.run_test()
coordinator.combine_html()
coordinator.collect_traces()