• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

testit-tms / adapters-python / 18490128607

14 Oct 2025 08:19AM UTC coverage: 36.89% (-0.02%) from 36.912%
18490128607

push

github

web-flow
fix: repair testit.step() state (#207)

0 of 2 new or added lines in 1 file covered. (0.0%)

1286 of 3486 relevant lines covered (36.89%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/testit-python-commons/src/testit_python_commons/step.py
1
from datetime import datetime
×
2
import logging
×
3
from functools import wraps
×
4
from typing import Any, Callable, TypeVar
×
5

6
from testit_python_commons.models.step_result import StepResult
×
7
from testit_python_commons.services import (
×
8
    TmsPluginManager,
9
    Utils
10
)
11

12

13
Func = TypeVar("Func", bound=Callable[..., Any])
×
14

15

16
# if we return title: "", it will be replaced to
17
# step name in fact later
18
def step(*args, **kwargs):
×
NEW
19
    if len(args) == 0:
×
NEW
20
        return StepContext("", None, {})
×
21

22
    if callable(args[0]):
×
23
        function = args[0]
×
24
        return StepContext(function.__name__, None, {})(function)
×
25
    else:
26
        title = get_title(args, kwargs)
×
27
        description = get_description(args, kwargs)
×
28

29
        return StepContext(title, description, {})
×
30

31

32
def get_title(args: tuple, kwargs: dict):
×
33
    if 'title' in kwargs:
×
34
        return kwargs['title']
×
35

36
    if len(args) > 0:
×
37
        if isinstance(args[0], str):
×
38
            return args[0]
×
39

40
        logging.error(f'Cannot to get step title: {args[1]}. The title must be of string type.')
×
41

42

43
def get_description(args: tuple, kwargs: dict):
×
44
    if 'description' in kwargs:
×
45
        return kwargs['description']
×
46

47
    if len(args) > 1:
×
48
        if isinstance(args[1], str):
×
49
            return args[1]
×
50
        logging.error(f'Cannot to get step description: {args[1]}. The description must be of string type.')
×
51

52

53
class StepContext:
×
54
    def __init__(self, title, description, parameters):
×
55
        self.__title = title
×
56
        self.__description = description
×
57
        self.__parameters = parameters
×
58

59
    def __enter__(self):
×
60
        self.__start_time = round(datetime.utcnow().timestamp() * 1000)
×
61
        self.__step_result = StepResult()
×
62

63
        self.__title = Utils.collect_parameters_in_string_attribute(self.__title, self.__parameters)
×
64
        self.__description = Utils.collect_parameters_in_string_attribute(self.__description, self.__parameters)
×
65

66
        self.__step_result\
×
67
            .set_title(self.__title)\
68
            .set_description(self.__description)\
69
            .set_parameters(
70
                Utils.exclude_self_parameter(self.__parameters)
71
            )
72

73
        logging.debug(f'Step "{self.__title}" was started')
×
74

75
        TmsPluginManager.get_step_manager().start_step(self.__step_result)
×
76

77
    def __exit__(self, exc_type, exc_val, exc_tb):
×
78
        outcome = 'Failed' if exc_type \
×
79
            else TmsPluginManager.get_plugin_manager().hook.get_pytest_check_outcome()[0] if \
80
            hasattr(TmsPluginManager.get_plugin_manager().hook, 'get_pytest_check_outcome') \
81
            else 'Passed'
82
        duration = round(datetime.utcnow().timestamp() * 1000) - self.__start_time
×
83

84
        self.__step_result\
×
85
            .set_outcome(outcome)\
86
            .set_duration(duration)
87

88
        TmsPluginManager.get_step_manager().stop_step()
×
89

90
    def __call__(self, function: Func) -> Func:
×
91
        @wraps(function)
×
92
        def impl(*args, **kwargs):
×
93
            __tracebackhide__ = True
×
94
            parameters = Utils.get_function_parameters(function, *args, **kwargs)
×
95

96
            title = self.__title if self.__title else function.__name__
×
97

98
            with StepContext(title, self.__description, parameters):
×
99
                return function(*args, **kwargs)
×
100

101
        return impl
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc