Skip to content

Base Tests

mercury.robust.basetests

RobustTest(name=None, *args, **kwargs)

Bases: ABC

Base class for the robust testing implementations. It keeps three attributes:

1) `_name` (str): name of the test. It can be specified when constructing the test, otherwise
    it will take the name of the class.
2) `_state `(TestState): state in which the test is found. Initially, NOT_EXECUTED
3) `_error_message` (str): After running the test, this contains an error message if the
    test fails or runs an exception
Source code in mercury/robust/basetests.py
37
38
39
40
def __init__(self, name=None, *args, **kwargs):
    self._name = name
    self._state = TestState.NOT_EXECUTED
    self._error_mesage = ""

run(*args, **kwargs)

Run the test, raising FailedTestError exception if it fails It must be implemented in subclasses

Source code in mercury/robust/basetests.py
64
65
66
67
68
69
def run(self, *args, **kwargs):
    """
    Run the test, raising FailedTestError exception if it fails
    It must be implemented in subclasses
    """
    pass

run_safe(*args, **kwargs)

Runs the test without raising FailedTestError exception. Instead, the attribute _state will store the state that has reached the test, and the attribute _error_message will contain a message in case that an error happens.

Source code in mercury/robust/basetests.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def run_safe(self, *args, **kwargs):
    """
    Runs the test without raising FailedTestError exception. Instead, the attribute
    `_state` will store the state that has reached the test, and the attribute
    `_error_message` will contain a message in case that an error happens.
    """
    try:
        self.run(*args, **kwargs)
        self._state = TestState.SUCCESS
        self._error_mesage = ""
    except FailedTestError as e:
        self._state = TestState.FAIL
        self._error_mesage = str(e)
    except Exception as e:
        self._state = TestState.EXCEPTION
        self._error_mesage = e.__repr__()

TestState

Bases: Enum

Enumeration class with the different states that a Test can be.