URL: https://github.com/freeipa/freeipa/pull/4953
Author: stanislavlevin
 Title: #4953: ipatests: Don't turn Pytest IPA deprecation warnings into errors
Action: opened

PR body:
"""
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
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/4953/head:pr4953
git checkout pr4953
From 4e289c5b23de8f3a603190b63c7990e39d5145c1 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <s...@altlinux.org>
Date: Wed, 29 Jul 2020 13:19:26 +0300
Subject: [PATCH] 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 <s...@altlinux.org>
---
 ipatests/conftest.py                                  |  5 +++++
 ipatests/pytest_ipa/deprecated_frameworks.py          | 11 ++++++-----
 .../test_ipatests_plugins/test_depr_frameworks.py     |  4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index ae0fbec16a..7a0ec70d43 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -26,6 +26,11 @@
 
 HERE = os.path.dirname(os.path.abspath(__file__))
 
+
+class PytestIPADeprecationWarning(pytest.PytestWarning, DeprecationWarning):
+    """Warning class for features that will be removed in a future version."""
+    pass
+
 pytest_plugins = [
     'ipatests.pytest_ipa.additional_config',
     'ipatests.pytest_ipa.deprecated_frameworks',
diff --git a/ipatests/pytest_ipa/deprecated_frameworks.py b/ipatests/pytest_ipa/deprecated_frameworks.py
index f638a3ae0a..17a5722dfe 100644
--- a/ipatests/pytest_ipa/deprecated_frameworks.py
+++ b/ipatests/pytest_ipa/deprecated_frameworks.py
@@ -28,6 +28,8 @@
 
 import pytest
 
+from conftest import PytestIPADeprecationWarning
+
 forbidden_module_scopes = [
     'setup_module',
     'setup_function',
@@ -47,7 +49,7 @@ 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(pytest.PytestDeprecationWarning(
+            item.warn(PytestIPADeprecationWarning(
                 "unittest is deprecated in favour of fixtures style"))
             continue
 
@@ -57,10 +59,9 @@ def xunit_depr_warn(item, attr, names):
                 method = getattr(obj, n, None)
                 fixtured = hasattr(method, '__pytest_wrapped__')
                 if method is not None and not fixtured:
-                    item.warn(
-                        pytest.PytestDeprecationWarning(
-                            "xunit style is deprecated in favour of "
-                            "fixtures style"))
+                    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)
diff --git a/ipatests/test_ipatests_plugins/test_depr_frameworks.py b/ipatests/test_ipatests_plugins/test_depr_frameworks.py
index a907dbc5d2..5d337c6939 100644
--- a/ipatests/test_ipatests_plugins/test_depr_frameworks.py
+++ b/ipatests/test_ipatests_plugins/test_depr_frameworks.py
@@ -83,7 +83,7 @@ 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 "
+        "* PytestIPADeprecationWarning: xunit style is deprecated in favour of "
         "fixtures style",
         "* 8 warning*",
     ])
@@ -93,7 +93,7 @@ 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 "
+        "* PytestIPADeprecationWarning: unittest is deprecated in favour of "
         "fixtures style",
         "* 1 warning*",
     ])
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to