turn create_result_file into classmethod

This commit is contained in:
Daniel 2023-12-10 18:00:36 +01:00
parent 016b88a68d
commit 3ffa2f8ecd

View file

@ -6,6 +6,8 @@ from typing import TYPE_CHECKING, Callable, NamedTuple
import pytest import pytest
from loguru import logger from loguru import logger
from pytest_abra import DirManager
if TYPE_CHECKING: if TYPE_CHECKING:
from pytest_abra.coordinator import Coordinator from pytest_abra.coordinator import Coordinator
from pytest_abra.env_manager import EnvFile from pytest_abra.env_manager import EnvFile
@ -89,12 +91,13 @@ class Runner:
if not condition_result: if not condition_result:
# test condition is defined but not met # test condition is defined but not met
logger.info(f"skipping {identifier_string} (test condition is 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 return
# test condition is undefined or not met # test condition is undefined or not met
logger.info(f"running {identifier_string}") logger.info(f"running {identifier_string}")
result = self._call_pytest(full_test_path) 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]): def _run_condition(self, condition_function: Callable[[ConditionArgs], bool]):
"""run the test condition function with multiple arguments""" """run the test condition function with multiple arguments"""
@ -174,15 +177,19 @@ class Runner:
return pytest.main(command_arguments) return pytest.main(command_arguments)
def _create_result_file( @classmethod
self, def create_result_file(
result: int, cls,
DIR: DirManager,
result: int | str,
identifier_string: str, identifier_string: str,
): ):
"""create result file to indicated passed/failed or skipped test""" """create result file to indicated passed/failed or skipped test"""
full_name = self.combine_names(self.result_int_to_str(result), identifier_string) if isinstance(result, int):
file_path = self.DIR.RESULTS / full_name 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 _: with open(file_path, "w") as _:
pass # create empty file pass # create empty file
@ -204,8 +211,6 @@ class Runner:
def result_int_to_str(result_int: int) -> str: def result_int_to_str(result_int: int) -> str:
"""converts the pytest exit code (int) into a meaningful string""" """converts the pytest exit code (int) into a meaningful string"""
match result_int: match result_int:
case -1:
return "skipped"
case 0: case 0:
return "passed" return "passed"
case _: case _: