From 9121128935712c114c69a2a615b38aa622ba6c61 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Dec 2023 17:15:12 +0100 Subject: [PATCH] remove PYTHONPATH stuff, add sys.path.append to create_runner_dict instead --- main.py | 6 ------ pytest_abra/coordinator.py | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 9de2d4f..00a451c 100644 --- a/main.py +++ b/main.py @@ -31,12 +31,6 @@ 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/pytest_abra/coordinator.py b/pytest_abra/coordinator.py index fb0f422..74c4ea2 100644 --- a/pytest_abra/coordinator.py +++ b/pytest_abra/coordinator.py @@ -1,5 +1,6 @@ import importlib import re +import sys from pathlib import Path from loguru import logger @@ -90,11 +91,17 @@ class Coordinator: "wordpress": RunnerWordpress, "nextcloud": RunnerNextcloud, } + + The Runner classes are automatically imported with importlib. The imports are successful + because recipes_dir is added to sys.path. """ RUNNER_DICT: dict[str, type["Runner"]] = dict() runner_discovery_pattern = re.compile("Runner.+") + # make it possible to import modules from recipes_dir + sys.path.append(recipes_dir.as_posix()) + for module_path in recipes_dir.rglob("*/runner*.py"): rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "") module = importlib.import_module(rel_path)