freeipa/ipatests/pytest_ipa/deprecated_frameworks.py
Stanislav Levin 55b7787ef5 ipatests: Don't turn Pytest IPA deprecation warnings into errors
With new Pytest 6.0 [0]:

> PytestDeprecationWarning are now errors by default.
Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type PytestDeprecationWarning now generate errors
instead of warning messages.

PytestWarnings are no longer marked as the part of public API, but as
internal warnings. It's unsafe to use bare PytestDeprecationWarning,
which is turned into the error on major releases.

[0]: https://github.com/pytest-dev/pytest/releases/tag/6.0.0

Fixes: https://pagure.io/freeipa/issue/8435
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
2020-07-29 15:10:00 -04:00

66 lines
2.2 KiB
Python

#
# Copyright (C) 2019 FreeIPA Contributors see COPYING for license
#
"""Warns about xunit/unittest/nose tests.
FreeIPA is a rather old project and hereby includes all the most
famous in the past and present Python test idioms. Of course,
this is difficult to play around all of them. For now, the runner
of the IPA's test suite is Pytest.
Pytest supports xunit style setups, unittest, nose tests. But this
support is limited and may be dropped in the future releases.
Worst of all is that the mixing of various test frameworks results
in weird conflicts and of course, is not widely tested. In other
words, there is a big risk. To eliminate this risk and to not pin
Pytest to 3.x branch IPA's tests were refactored.
This plugin is intended to issue warnings on collecting tests,
which employ unittest/nose frameworks or xunit style.
To treat these warnings as errors it's enough to run Pytest with:
-W error:'xunit style is deprecated':pytest.PytestIPADeprecationWarning
"""
from unittest import TestCase
from ipatests.conftest import PytestIPADeprecationWarning
forbidden_module_scopes = [
'setup_module',
'setup_function',
'teardown_module',
'teardown_function',
]
forbidden_class_scopes = [
'setup_class',
'setup_method',
'teardown_class',
'teardown_method',
]
def pytest_collection_finish(session):
for item in session.items:
cls = getattr(item, 'cls', None)
if cls is not None and issubclass(cls, TestCase):
item.warn(PytestIPADeprecationWarning(
"unittest is deprecated in favour of fixtures style"))
continue
def xunit_depr_warn(item, attr, names):
for n in names:
obj = getattr(item, attr, None)
method = getattr(obj, n, None)
fixtured = hasattr(method, '__pytest_wrapped__')
if method is not None and not fixtured:
item.warn(PytestIPADeprecationWarning(
"xunit style is deprecated in favour of "
"fixtures style"))
xunit_depr_warn(item, 'module', forbidden_module_scopes)
xunit_depr_warn(item, 'cls', forbidden_class_scopes)