e2e_tests/pytest_abra/cli.py
Daniel 2dd765a974 various (#16)
* add full integration test of cli / pytest_abra with all tests

* save path of runner_*.py in runner subclass to improve test discovery -> allows for same test name in two different runners

* reorganize output dir names

* use URL fixture everywhere

* rework coordinator interface

* add --session_id to cli args

* add log results table

* plenty of refactoring

* add assert messages

* add plenty of tests

* add /docs dir with plenty of documentation

* fix authentik setup

* add authentik cleanup, remove test user

* add random test user credential generation and integrate into test routine. random creds are saved to STATES

Reviewed-on: local-it-infrastructure/e2e_tests#16
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
2023-12-14 14:03:58 +01:00

59 lines
2.3 KiB
Python

import argparse
import os
from pathlib import Path
import pkg_resources # type: ignore
from loguru import logger
from pytest_abra import Coordinator
from pytest_abra.dir_manager import DirManager
from pytest_abra.utils import get_session_id
def get_version():
return pkg_resources.get_distribution("pytest_abra").version
def run():
parser = argparse.ArgumentParser()
parser.add_argument("--version", "-V", action="version", version=get_version(), help="output the version number")
parser.add_argument("--env_paths", type=str, help="List of loaded env files separated with ;", required=True)
parser.add_argument("--recipes_dir", type=Path, help="Dir of abra recipes and respective runners", required=True)
parser.add_argument("--output_dir", type=Path, help="Dir of test outputs", required=True)
parser.add_argument("--timeout", type=int, help="Set Playwright timeout in ms", default=20_000)
parser.add_argument("--debug", action="store_true", help="Enable Playwright debug mode")
parser.add_argument("--resume", action="store_true", help="Re-run the most recent test, skipping passed tests")
parser.add_argument("--session_id", help="Session dir name (inside output_dir). Overwrites --resume")
args = parser.parse_args()
env_paths = [Path(s) for s in args.env_paths.split(";")]
# -------------------------- enable playwright debug ------------------------- #
if args.debug:
os.environ["PWDEBUG"] = "1"
# ----------------------------- define session_id ---------------------------- #
session_id = get_session_id(args.output_dir, args.resume, args.session_id)
# ------------------------------- setup logging ------------------------------ #
# todo: move to Coordinator
DIR = DirManager(output_dir=args.output_dir, session_id=session_id)
log_file = DIR.RESULTS / "coordinator.log"
logger.add(log_file)
# ---------------------------- initialize and run ---------------------------- #
coordinator = Coordinator(
env_paths=env_paths,
output_dir=args.output_dir,
session_id=session_id,
recipes_dir=args.recipes_dir,
timeout=args.timeout,
)
coordinator.prepare_tests()
coordinator.run_tests()
coordinator.combine_html()
coordinator.collect_traces()