diff --git a/pytest_abra/coordinator.py b/pytest_abra/coordinator.py index f1e557a..47a4a57 100644 --- a/pytest_abra/coordinator.py +++ b/pytest_abra/coordinator.py @@ -2,7 +2,6 @@ import importlib import re import sys from pathlib import Path -from typing import NamedTuple from loguru import logger @@ -13,11 +12,6 @@ from pytest_abra.runner import Runner from pytest_abra.utils import rmtree -class RunnerMeta(NamedTuple): - cls: type[Runner] - path: Path - - class Coordinator: def __init__( self, @@ -60,9 +54,8 @@ class Coordinator: """Creates an instance of the correct Runner class for each given env file""" runners: list[Runner] = [] for index, env_file in enumerate(env_files): - meta = self.RUNNER_DICT[env_file.env_config["TYPE"]] - RunnerClass = meta.cls - runners.append(RunnerClass(coordinator=self, runner_index=index, runner_dir=meta.path)) + RunnerClass = self.RUNNER_DICT[env_file.env_config["TYPE"]] + runners.append(RunnerClass(coordinator=self, runner_index=index)) return runners def combine_html(self) -> None: @@ -96,14 +89,14 @@ class Coordinator: rmtree(trace_root_dir) @staticmethod - def create_runner_dict(recipes_dir: Path) -> dict[str, RunnerMeta]: + def create_runner_dict(recipes_dir: Path) -> dict[str, type[Runner]]: """Creates a dictionary holding all the RunnerClasses that can be discovered in recipes_dir The Runner classes are automatically imported with importlib. The imports are successful because recipes_dir is added to sys.path. """ - RUNNER_DICT: dict[str, RunnerMeta] = dict() + RUNNER_DICT: dict[str, type[Runner]] = dict() runner_discovery_pattern = re.compile("Runner.+") # make it possible to import modules from recipes_dir @@ -116,5 +109,6 @@ class Coordinator: assert len(runner_class_names) == 1 runner_class_name = runner_class_names[0] RunnerClass: type[Runner] = getattr(module, runner_class_name) - RUNNER_DICT[RunnerClass.env_type] = RunnerMeta(cls=RunnerClass, path=module_path) + RunnerClass._tests_path = module_path + RUNNER_DICT[RunnerClass.env_type] = RunnerClass return RUNNER_DICT diff --git a/pytest_abra/env_manager.py b/pytest_abra/env_manager.py index 2490462..7de06e4 100644 --- a/pytest_abra/env_manager.py +++ b/pytest_abra/env_manager.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, NamedTuple from dotenv import dotenv_values if TYPE_CHECKING: - from pytest_abra.coordinator import RunnerMeta from pytest_abra.dir_manager import DirManager from pytest_abra.runner import Runner @@ -25,7 +24,7 @@ class DependencyRule(NamedTuple): class EnvManager: - def __init__(self, env_paths: list[Path], RUNNER_DICT: dict[str, "RunnerMeta"]): + def __init__(self, env_paths: list[Path], RUNNER_DICT: dict[str, type[Runner]]): self.env_files: list[EnvFile] = self._get_env_files(env_paths) self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files, RUNNER_DICT) self.env_files = self.sort_env_files_by_rule(self.env_files, self.dependency_rules) @@ -43,10 +42,10 @@ class EnvManager: return env_files @staticmethod - def _get_dependency_rules(env_files: list[EnvFile], RUNNER_DICT: dict[str, "RunnerMeta"]) -> list[DependencyRule]: + def _get_dependency_rules(env_files: list[EnvFile], RUNNER_DICT: dict[str, type[Runner]]) -> list[DependencyRule]: dependency_rules: list[DependencyRule] = [] for env_file in env_files: - child_runner_class = RUNNER_DICT[env_file.env_type].cls + child_runner_class = RUNNER_DICT[env_file.env_type] for dependency in child_runner_class.dependencies: dependency_rule = DependencyRule(child=child_runner_class.env_type, dependency=dependency) dependency_rules.append(dependency_rule) diff --git a/pytest_abra/runner.py b/pytest_abra/runner.py index d2424ea..b193795 100644 --- a/pytest_abra/runner.py +++ b/pytest_abra/runner.py @@ -1,7 +1,7 @@ import os from dataclasses import dataclass from pathlib import Path -from typing import TYPE_CHECKING, Callable, NamedTuple +from typing import TYPE_CHECKING, Callable, NamedTuple, Optional import pytest from loguru import logger @@ -31,11 +31,11 @@ class Runner: tests: list[Test] = [] cleanups: list[Test] = [] dependencies: list[str] = [] + _tests_path: Optional[Path] = None - def __init__(self, coordinator: "Coordinator", runner_index: int, runner_dir: Path): + def __init__(self, coordinator: "Coordinator", runner_index: int): self.coordinator = coordinator self.runner_index = runner_index - self.runner_dir = runner_dir self.DIR = coordinator.DIR self.ENV = coordinator.ENV