diff --git a/tests/requirements.py b/tests/requirements.py index 49ab421d62eb..8fd2f2f05377 100644 --- a/tests/requirements.py +++ b/tests/requirements.py @@ -2,31 +2,11 @@ # # SPDX-License-Identifier: MIT -import pytest - - -def mark_requirement(requirement): - def wrapper(test_func): - @pytest.mark.components(DatumaroComponent.Datumaro) - @pytest.mark.component - @pytest.mark.priority_medium - @pytest.mark.reqids(requirement) - def test_wrapper(*args, **kwargs): - return test_func(*args, **kwargs) - return test_wrapper - return wrapper +import typing -def mark_bug(bugs): - def wrapper(test_func): - @pytest.mark.components(DatumaroComponent.Datumaro) - @pytest.mark.component - @pytest.mark.priority_medium - @pytest.mark.bugs(bugs) - def test_wrapper(*args, **kwargs): - return test_func(*args, **kwargs) - return test_wrapper - return wrapper +from attr import attrs +import pytest class DatumaroComponent: Datumaro = "datumaro" @@ -47,3 +27,33 @@ class Requirements: class SkipMessages: NOT_IMPLEMENTED = "NOT IMPLEMENTED" + + +@attrs(auto_attribs=True) +class _CombinedDecorator: + decorators: typing.List[typing.Callable] + + def __call__(self, function): + for d in reversed(self.decorators): + function = d(function) + + return function + + +_SHARED_DECORATORS = [ + pytest.mark.components(DatumaroComponent.Datumaro), + pytest.mark.component, + pytest.mark.priority_medium, +] + +def mark_requirement(requirement): + return _CombinedDecorator([ + *_SHARED_DECORATORS, + pytest.mark.reqids(requirement), + ]) + +def mark_bug(bugs): + return _CombinedDecorator([ + *_SHARED_DECORATORS, + pytest.mark.bugs(bugs), + ])