From 2cb4a9d526aeb598301b24088ae1d5c6aa623b75 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 24 Nov 2023 11:30:52 +0100 Subject: [PATCH] Easier setup by executing main from root working directory --- main.py | 6 ++++++ src/conftest.py | 3 ++- src/runner.py | 5 +++-- src/setup-deprecated/setup_authentik.py | 2 +- src/tests_authentik/runner_authentik.py | 4 ++-- src/tests_authentik/setup_authentik.py | 2 +- src/tests_wordpress/conftest.py | 2 +- src/tests_wordpress/runner_wordpress.py | 2 +- src/{main.py => wrapper.py} | 18 ++++++------------ 9 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 main.py rename src/{main.py => wrapper.py} (80%) diff --git a/main.py b/main.py new file mode 100644 index 0000000..4b0289a --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +from src.wrapper import ENV_FILES, Wrapper + +session_id = Wrapper.get_session_id() +wrapper = Wrapper(ENV_FILES, session_id=session_id) +wrapper.setup_test() +wrapper.run_test() diff --git a/src/conftest.py b/src/conftest.py index 03035a0..55b819f 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -8,11 +8,12 @@ from pathlib import Path import pytest -from dirmanager import DirManager from dotenv import dotenv_values from icecream import ic from playwright.sync_api import BrowserContext +from src.dirmanager import DirManager + pytest_plugins = [ # "setup.setup_authentik", "tests_authentik.authentik_plugin" diff --git a/src/runner.py b/src/runner.py index b987e60..07c8848 100644 --- a/src/runner.py +++ b/src/runner.py @@ -2,10 +2,11 @@ from pathlib import Path from typing import Callable, Optional, TypedDict import pytest -from dirmanager import DirManager from dotenv import dotenv_values from icecream import ic +from src.dirmanager import DirManager + class SubTest(TypedDict): condition: Callable[[Path], bool] @@ -13,7 +14,7 @@ class SubTest(TypedDict): class Runner: - test_dir_name: Optional[Path] = None + test_dir_name: Optional[str] = None main_test_name: Optional[str] = None sub_tests: list[SubTest] = [] dependencies: list[str] = [] diff --git a/src/setup-deprecated/setup_authentik.py b/src/setup-deprecated/setup_authentik.py index acb7e1b..3166063 100644 --- a/src/setup-deprecated/setup_authentik.py +++ b/src/setup-deprecated/setup_authentik.py @@ -5,7 +5,7 @@ import pytest from icecream import ic from playwright.sync_api import Browser, Locator, expect -cred_file = Path("../credentials.json") +cred_file = Path("credentials.json") with open(cred_file, "r") as f: CREDENTIALS = json.load(f) diff --git a/src/tests_authentik/runner_authentik.py b/src/tests_authentik/runner_authentik.py index efd82fe..bf49077 100644 --- a/src/tests_authentik/runner_authentik.py +++ b/src/tests_authentik/runner_authentik.py @@ -1,7 +1,7 @@ from pathlib import Path -from runner import Runner, SubTest -from tests_authentik.setup_authentik import setup_authentik +from src.runner import Runner, SubTest +from src.tests_authentik.setup_authentik import setup_authentik def condition_always_true(dotenv_path: Path) -> bool: diff --git a/src/tests_authentik/setup_authentik.py b/src/tests_authentik/setup_authentik.py index 4691f2c..c88d221 100644 --- a/src/tests_authentik/setup_authentik.py +++ b/src/tests_authentik/setup_authentik.py @@ -5,7 +5,7 @@ from pathlib import Path from icecream import ic from playwright.sync_api import Browser, BrowserContext, Locator, Page, expect, sync_playwright -cred_file = Path("../credentials.json") +cred_file = Path("credentials.json") with open(cred_file, "r") as f: CREDENTIALS = json.load(f) diff --git a/src/tests_wordpress/conftest.py b/src/tests_wordpress/conftest.py index d78bb85..0dd75fc 100644 --- a/src/tests_wordpress/conftest.py +++ b/src/tests_wordpress/conftest.py @@ -12,7 +12,7 @@ from playwright.sync_api import Browser, Locator, expect, sync_playwright # browser = playwright.chromium.launch(headless=False) -cred_file = Path("../credentials.json") +cred_file = Path("credentials.json") with open(cred_file, "r") as f: CREDENTIALS = json.load(f) diff --git a/src/tests_wordpress/runner_wordpress.py b/src/tests_wordpress/runner_wordpress.py index 00c7642..eddccfa 100644 --- a/src/tests_wordpress/runner_wordpress.py +++ b/src/tests_wordpress/runner_wordpress.py @@ -1,6 +1,6 @@ from pathlib import Path -from runner import Runner, SubTest +from src.runner import Runner, SubTest def condition_always_true(dotenv_path: Path) -> bool: diff --git a/src/main.py b/src/wrapper.py similarity index 80% rename from src/main.py rename to src/wrapper.py index a05431b..b524969 100644 --- a/src/main.py +++ b/src/wrapper.py @@ -2,17 +2,18 @@ from datetime import datetime from pathlib import Path from typing import Protocol -from dirmanager import DirManager from dotenv import dotenv_values from icecream import ic -from tests_authentik.runner_authentik import RunnerAuthentik -from tests_wordpress.runner_wordpress import RunnerWordpress + +from src.dirmanager import DirManager +from src.tests_authentik.runner_authentik import RunnerAuthentik +from src.tests_wordpress.runner_wordpress import RunnerWordpress TESTS_DIR = Path("../tests") ENV_FILES = [ - Path("../envfiles/login.test.dev.local-it.cloud.env"), # authentik - # Path("../envfiles/blog.test.dev.local-it.cloud.env"), # wordpress + Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik + # Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress ] @@ -69,10 +70,3 @@ class Wrapper: def get_session_id() -> str: current_datetime = datetime.now() return current_datetime.strftime("%Y-%m-%d-%H-%M-%S") - - -if __name__ == "__main__": - session_id = Wrapper.get_session_id() - wrapper = Wrapper(ENV_FILES, session_id=session_id) - wrapper.setup_test() - wrapper.run_test()