From 3ffa2f8ecdfd12c8cb5c40ad10505527c7bdc421 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 10 Dec 2023 18:00:36 +0100 Subject: [PATCH] turn create_result_file into classmethod --- pytest_abra/runner.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pytest_abra/runner.py b/pytest_abra/runner.py index 3d75562..fb6d270 100644 --- a/pytest_abra/runner.py +++ b/pytest_abra/runner.py @@ -6,6 +6,8 @@ from typing import TYPE_CHECKING, Callable, NamedTuple import pytest from loguru import logger +from pytest_abra import DirManager + if TYPE_CHECKING: from pytest_abra.coordinator import Coordinator from pytest_abra.env_manager import EnvFile @@ -89,12 +91,13 @@ class Runner: if not condition_result: # test condition is defined but not met logger.info(f"skipping {identifier_string} (test condition is not met)") + self.create_result_file(self.DIR, result="skipped", identifier_string=identifier_string) return # test condition is undefined or not met logger.info(f"running {identifier_string}") result = self._call_pytest(full_test_path) - self._create_result_file(result=result, identifier_string=identifier_string) + self.create_result_file(self.DIR, result=result, identifier_string=identifier_string) def _run_condition(self, condition_function: Callable[[ConditionArgs], bool]): """run the test condition function with multiple arguments""" @@ -174,15 +177,19 @@ class Runner: return pytest.main(command_arguments) - def _create_result_file( - self, - result: int, + @classmethod + def create_result_file( + cls, + DIR: DirManager, + result: int | str, identifier_string: str, ): """create result file to indicated passed/failed or skipped test""" - full_name = self.combine_names(self.result_int_to_str(result), identifier_string) - file_path = self.DIR.RESULTS / full_name + if isinstance(result, int): + result = cls.result_int_to_str(result) + full_name = cls.combine_names(result, identifier_string) + file_path = DIR.RESULTS / full_name with open(file_path, "w") as _: pass # create empty file @@ -204,8 +211,6 @@ class Runner: def result_int_to_str(result_int: int) -> str: """converts the pytest exit code (int) into a meaningful string""" match result_int: - case -1: - return "skipped" case 0: return "passed" case _: