From d2cfc089c36f59f773f54648ff128c74bb72c3f2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Dec 2023 13:02:39 +0100 Subject: [PATCH] fix-docker (#10) * fix docker -> use "pip install -e ." in installation -> add symlinks in docker image -> docker / non docker execution can run same main.py + cli * remove sh scripts * remove requirements.txt Reviewed-on: https://git.local-it.org/local-it-infrastructure/e2e_tests/pulls/10 Co-authored-by: Daniel Co-committed-by: Daniel --- Dockerfile | 12 +++++++++--- README.md | 9 +++++---- main.py | 7 +++++++ pyproject.toml | 6 ++---- pytest_abra/cli.py | 7 +++---- requirements.txt | 9 --------- run_abratest.sh | 6 ------ test_abratest.sh | 7 ------- 8 files changed, 26 insertions(+), 37 deletions(-) delete mode 100644 requirements.txt delete mode 100644 run_abratest.sh delete mode 100644 test_abratest.sh diff --git a/Dockerfile b/Dockerfile index 8a7efdd..609f0a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,13 @@ RUN playwright install RUN playwright install-deps -COPY ./requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt +COPY . /code -WORKDIR /code \ No newline at end of file +WORKDIR /code + +RUN pip install --no-cache-dir -e . + +RUN rm -rf /code + +RUN ln -s /code/recipes /recipes +RUN ln -s /code/envfiles /envfiles diff --git a/README.md b/README.md index d3d3604..3418450 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ You can run pytest-abra with and without Docker. Choose now and follow the steps Create a python environment and install all dependencies via ```bash -pip install -r requirements.txt +pip install -e . playwright install ``` @@ -40,7 +40,8 @@ python main.py ```bash docker compose build # build the image -docker compose run --rm app ./run_pytest-abra.sh # run pytest-abra +docker compose run --rm app python main.py # run pytest-abra +docker compose run --rm -it app /bin/bash # debug the container ``` Force rebuild with cache @@ -49,7 +50,7 @@ Force rebuild with cache docker-compose up --build ``` -Force rebuild wtihtout cache +Force rebuild without cache ```bash docker-compose build --no-cache @@ -68,5 +69,5 @@ playwright codegen demo.playwright.dev/todomvc ```bash pytest # test pytest-abra pytest --collect-only # debug test pytest-abra -docker compose run --rm app ./test_pytest-abra.sh # test pytest-abra +docker compose run --rm app pytest # run pytest-abra ``` diff --git a/main.py b/main.py index e7b02a2..9de2d4f 100644 --- a/main.py +++ b/main.py @@ -31,6 +31,13 @@ ENV_PATHS = ";".join([x.as_posix() for x in ENV_FILES]) RECIPES_DIR = Path("../recipes").resolve() OUTPUT_DIR = Path("./test-output").resolve() +# -------------------------------- pythonpath -------------------------------- # + +# add recipes dir to pythonpath, so that python imports from there are possible +# the custom classes of Runner will be imported from there +os.environ["PYTHONPATH"] = RECIPES_DIR.as_posix() + +# ------------------------------------ run ----------------------------------- # subprocess.run( [ diff --git a/pyproject.toml b/pyproject.toml index c951457..20d9b07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,10 +25,8 @@ dependencies = [ "icecream", ] -[project.entry_points] -pytest11 = [ - "pytest_abra = pytest_abra.pytest_abra", -] +[project.entry-points.pytest11] +pytest_abra = "pytest_abra.pytest_abra" [project.scripts] abratest = "pytest_abra.cli:run" diff --git a/pytest_abra/cli.py b/pytest_abra/cli.py index 2b1dfa7..0d82951 100644 --- a/pytest_abra/cli.py +++ b/pytest_abra/cli.py @@ -11,14 +11,13 @@ 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=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("--env_paths", type=str, help="List of loaded env files separated with ;", required=True) + parser.add_argument("--recipes_dir", type=Path, help="List of loaded env files separated with ;", required=True) + parser.add_argument("--output_dir", type=Path, help="List of loaded env files separated with ;", 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") args = parser.parse_args() - ENV_FILES = [Path(s) for s in args.env_paths.split(";")] # -------------------------- enable playwright debug ------------------------- # diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index be7218a..0000000 --- a/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -pytest -pytest-html -pytest-playwright -python-dotenv -icecream -loguru -beautifulsoup4 -imbox -hatchling \ No newline at end of file diff --git a/run_abratest.sh b/run_abratest.sh deleted file mode 100644 index ddffb80..0000000 --- a/run_abratest.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -RECIPES_PATH=$PWD/recipes -export PYTHONPATH=${PYTHONPATH}:$RECIPES_PATH - -python main.py \ No newline at end of file diff --git a/test_abratest.sh b/test_abratest.sh deleted file mode 100644 index d7abaaa..0000000 --- a/test_abratest.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -PWD_PATH=$PWD -RECIPES_PATH=$PWD/recipes -export PYTHONPATH=$PWD_PATH:$RECIPES_PATH - -pytest \ No newline at end of file