add timeout parameter to cli and to pytest_abra

This commit is contained in:
Daniel 2023-12-07 01:40:35 +01:00
parent a499891fe8
commit 8a136e5e6c
4 changed files with 19 additions and 17 deletions

View file

@ -32,8 +32,6 @@ RECIPES_DIR = Path("../recipes").resolve()
OUTPUT_DIR = Path("./test-output").resolve()
# exit()
subprocess.run(
[
"pytest-abra",

View file

@ -12,22 +12,15 @@ from pytest_abra.utils import get_datetime_string
def run():
parser = argparse.ArgumentParser()
parser.add_argument("--env_paths", type=str, help="List of loaded env files separated with ;")
parser.add_argument("--recipes_dir", type=str, help="List of loaded env files separated with ;")
parser.add_argument("--output_dir", type=str, help="List of loaded env files separated with ;")
parser.add_argument("--recipes_dir", type=Path, help="List of loaded env files separated with ;")
parser.add_argument("--output_dir", type=Path, help="List of loaded env files separated with ;")
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, only running tests without status 'passed'"
)
parser.add_argument("--resume", action="store_true", help="Re-run the most recent test, skipping passed tests")
args = parser.parse_args()
ENV_FILES = [Path(s) for s in args.env_paths.split(";")]
# ----------------------------- define ouptut dir ---------------------------- #
RECIPES_DIR = Path(args.recipes_dir)
OUTPUT_DIR = Path(args.output_dir)
# -------------------------- enable playwright debug ------------------------- #
if args.debug:
@ -43,14 +36,19 @@ def run():
# ------------------------------- setup logging ------------------------------ #
DIR = DirManager(output_dir=OUTPUT_DIR, session_id=session_id)
# todo: move to Coordinator
DIR = DirManager(output_dir=args.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
env_paths_list=ENV_FILES,
output_dir=args.output_dir,
session_id=session_id,
recipes_dir=args.recipes_dir,
timeout=args.timeout,
)
coordinator.setup_test()
coordinator.run_test()

View file

@ -12,7 +12,9 @@ from pytest_abra.utils import rmtree
class Coordinator:
def __init__(self, env_paths_list: list[Path], output_dir: Path, session_id: str, recipes_dir: Path) -> None:
def __init__(
self, env_paths_list: list[Path], output_dir: Path, session_id: str, recipes_dir: Path, timeout: int
) -> None:
# logging
out_string = "".join([e.name + "\n" for e in env_paths_list])
out_string += f"output_dir = {output_dir}\n"
@ -22,6 +24,7 @@ class Coordinator:
self.RUNNER_DICT = self.create_runner_dict(recipes_dir)
self.DIR = DirManager(output_dir=output_dir, session_id=session_id, recipes_dir=recipes_dir)
self.ENV = EnvManager(env_paths_list, self.RUNNER_DICT)
self.TIMEOUT = timeout
def setup_test(self) -> None:
logger.info("calling setup_test()")

View file

@ -133,6 +133,9 @@ class Runner:
command_arguments.append("--session_id")
command_arguments.append(self.DIR.session_id)
command_arguments.append("--timeout")
command_arguments.append(str(self.coordinator.TIMEOUT))
# artifacts dir from pytest
# warning: https://github.com/microsoft/playwright-pytest/issues/111
# --output only works with the given context and page fixture
@ -146,7 +149,7 @@ class Runner:
# command_arguments.append("on")
# Disable capturing. With -s set, prints will go to console as if pytest is not there.
command_arguments.append("-s")
# command_arguments.append("-s")
# headed
# command_arguments.append("--headed")