mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
tests(deprecated):
add new check_deprecated context manager for version check, use mark.parametrize from pytest for observer deprecation tests
This commit is contained in:
parent
6cbf9cdde6
commit
c083fcd99a
4 changed files with 40 additions and 22 deletions
26
tests/deprecated.py
Normal file
26
tests/deprecated.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from contextlib import contextmanager
|
||||
from typing import Type
|
||||
|
||||
import pytest
|
||||
from packaging import version
|
||||
|
||||
import aiogram
|
||||
|
||||
|
||||
@contextmanager
|
||||
def check_deprecated(
|
||||
max_version: str, exception: Type[Exception], warning: Type[Warning] = DeprecationWarning,
|
||||
) -> None:
|
||||
"""
|
||||
Should be used for modules that are being deprecated or already removed from aiogram
|
||||
"""
|
||||
|
||||
parsed_max_version = version.parse(max_version)
|
||||
current_version = version.parse(aiogram.__version__)
|
||||
|
||||
if parsed_max_version <= current_version:
|
||||
with pytest.raises(exception):
|
||||
yield
|
||||
else:
|
||||
with pytest.warns(warning, match=max_version):
|
||||
yield
|
||||
Loading…
Add table
Add a link
Reference in a new issue