wip: add cli command with [project.scripts]
This commit is contained in:
parent
35908ddc00
commit
93106df3b9
3 changed files with 69 additions and 80 deletions
|
|
@ -31,7 +31,7 @@ pytest11 = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
abrademo = "pytest_abra.main:run"
|
pytest-abra = "pytest_abra.cli:run"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
|
|
|
||||||
68
pytest_abra/cli.py
Normal file
68
pytest_abra/cli.py
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from pytest_abra.coordinator import Coordinator
|
||||||
|
from pytest_abra.dir_manager import DirManager
|
||||||
|
from pytest_abra.utils import get_datetime_string
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--debug", action="store_true", help="Enable Playwright debug mode")
|
||||||
|
parser.add_argument("--repeat", action="store_true", help="Re-run the most recent test")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# ----------------------------- 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_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
|
||||||
|
]
|
||||||
|
|
||||||
|
# ----------------------------- define ouptut dir ---------------------------- #
|
||||||
|
|
||||||
|
OUTPUT_DIR = Path("./test-output").resolve()
|
||||||
|
RECIPES_DIR = Path("../recipes").resolve()
|
||||||
|
|
||||||
|
# -------------------------- enable playwright debug ------------------------- #
|
||||||
|
|
||||||
|
if args.debug:
|
||||||
|
os.environ["PWDEBUG"] = "1"
|
||||||
|
|
||||||
|
# ----------------------------- define session_id ---------------------------- #
|
||||||
|
|
||||||
|
session_id = "test-" + get_datetime_string()
|
||||||
|
if args.repeat:
|
||||||
|
# look for previous session_id
|
||||||
|
pass
|
||||||
|
# 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
|
||||||
|
)
|
||||||
|
coordinator.setup_test()
|
||||||
|
coordinator.run_test()
|
||||||
|
coordinator.combine_html()
|
||||||
|
coordinator.collect_traces()
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
from pytest_abra.coordinator import Coordinator
|
|
||||||
from pytest_abra.dir_manager import DirManager
|
|
||||||
from pytest_abra.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_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
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------- 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)
|
|
||||||
|
|
||||||
for key, value in CREDENTIALS.items():
|
|
||||||
os.environ[key] = value
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------- enable playwright debug ------------------------- #
|
|
||||||
|
|
||||||
|
|
||||||
# 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
|
|
||||||
)
|
|
||||||
coordinator.setup_test()
|
|
||||||
coordinator.run_test()
|
|
||||||
coordinator.combine_html()
|
|
||||||
coordinator.collect_traces()
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue