kiwi-el8/test/unit/api_helper_test.py
Alexandre Detiste fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00

34 lines
866 B
Python

from pytest import raises
from unittest.mock import patch
from kiwi.api_helper import (
obsolete,
decommissioned
)
@decommissioned
def method_decommissioned():
# Implementation has been deleted
pass
@obsolete(decommission_at='2025-01-28', version="1.2.3")
def method_obsolete():
return 'I still exist'
class TestApiHelpers:
def test_method_decommissioned(self):
with raises(DeprecationWarning):
method_decommissioned()
@patch('warnings.warn')
def test_method_obsolete(self, mock_warnings_warn):
warning_message = (
"Function 'method_obsolete' is marked obsolete "
"since version '1.2.3' and will be decommissioned "
"at: 2025-01-28"
)
assert method_obsolete() == 'I still exist'
mock_warnings_warn.assert_called_once_with(warning_message)