mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
8c7447fd42
This Pytest plugin is intended to issue warnings on collecting tests, which employ unittest/nose frameworks or xunit style. For example, this may look like: """ test_a/test_xunit.py:25 test_a/test_xunit.py:25: PytestDeprecationWarning: xunit style is deprecated def test_foo_bar(self): test_b/test_unittest.py:7 test_b/test_unittest.py:7: PytestDeprecationWarning: unittest is deprecated def test_foo_bar(self): """ To treat these warnings as errors it's enough to run Pytest with: -W error:'xunit style is deprecated':pytest.PytestDeprecationWarning Related: https://pagure.io/freeipa/issue/7989 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Christian Heimes <cheimes@redhat.com>
100 lines
2.3 KiB
Python
100 lines
2.3 KiB
Python
#
|
|
# Copyright (C) 2019 FreeIPA Contributors see COPYING for license
|
|
#
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def ipa_testdir(testdir):
|
|
"""
|
|
Create conftest within testdir.
|
|
"""
|
|
testdir.makeconftest(
|
|
"""
|
|
pytest_plugins = ["ipatests.pytest_ipa.deprecated_frameworks"]
|
|
"""
|
|
)
|
|
return testdir
|
|
|
|
|
|
@pytest.fixture
|
|
def xunit_testdir(ipa_testdir):
|
|
"""
|
|
Create xnit style test module within testdir.
|
|
"""
|
|
ipa_testdir.makepyfile("""
|
|
def setup_module():
|
|
pass
|
|
def teardown_module():
|
|
pass
|
|
def setup_function():
|
|
pass
|
|
def teardown_function():
|
|
pass
|
|
|
|
class TestClass:
|
|
@classmethod
|
|
def setup_class(cls):
|
|
pass
|
|
@classmethod
|
|
def teardown_class(cls):
|
|
pass
|
|
def setup_method(self):
|
|
pass
|
|
def teardown_method(self):
|
|
pass
|
|
def test_m(self):
|
|
pass
|
|
""")
|
|
return ipa_testdir
|
|
|
|
|
|
@pytest.fixture
|
|
def unittest_testdir(ipa_testdir):
|
|
"""
|
|
Create unittest style test module within testdir.
|
|
"""
|
|
ipa_testdir.makepyfile("""
|
|
import unittest
|
|
def setUpModule():
|
|
pass
|
|
def tearDownModule():
|
|
pass
|
|
class TestClass(unittest.TestCase):
|
|
@classmethod
|
|
def setUp(self):
|
|
pass
|
|
def tearDown(self):
|
|
pass
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
pass
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
pass
|
|
def test_m(self):
|
|
pass
|
|
""")
|
|
return ipa_testdir
|
|
|
|
|
|
def test_xunit(xunit_testdir):
|
|
result = xunit_testdir.runpytest()
|
|
result.assert_outcomes(passed=1)
|
|
result.stdout.fnmatch_lines([
|
|
"* PytestDeprecationWarning: xunit style is deprecated in favour of "
|
|
"fixtures style",
|
|
"* 8 warning*",
|
|
])
|
|
|
|
|
|
def test_unittest(unittest_testdir):
|
|
result = unittest_testdir.runpytest()
|
|
result.assert_outcomes(passed=1)
|
|
result.stdout.fnmatch_lines([
|
|
"* PytestDeprecationWarning: unittest is deprecated in favour of "
|
|
"fixtures style",
|
|
"* 1 warning*",
|
|
])
|