URL: https://github.com/freeipa/freeipa/pull/4957
Author: rcritten
 Title: #4957: [Backport][ipa-4-8] ipatests: Don't turn Pytest IPA deprecation 
warnings into errors
Action: opened

PR body:
"""
This PR was opened automatically because PR #4953 was pushed to master and 
backport to ipa-4-8 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/4957/head:pr4957
git checkout pr4957
From 3d498c4341798646d2008c12a3981e9bc2d7599a 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                                |  4 ++++
 ipatests/pytest_ipa/deprecated_frameworks.py        | 13 ++++++-------
 .../test_ipatests_plugins/test_depr_frameworks.py   |  4 ++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index ae0fbec16a..1fed595424 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -26,6 +26,10 @@
 
 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."""
+
 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..9e179aaf7c 100644
--- a/ipatests/pytest_ipa/deprecated_frameworks.py
+++ b/ipatests/pytest_ipa/deprecated_frameworks.py
@@ -21,12 +21,12 @@
 
 To treat these warnings as errors it's enough to run Pytest with:
 
--W error:'xunit style is deprecated':pytest.PytestDeprecationWarning
+-W error:'xunit style is deprecated':pytest.PytestIPADeprecationWarning
 
 """
 from unittest import TestCase
 
-import pytest
+from ipatests.conftest import PytestIPADeprecationWarning
 
 forbidden_module_scopes = [
     'setup_module',
@@ -47,7 +47,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 +57,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