URL: https://github.com/freeipa/freeipa/pull/828
Author: tiran
 Title: #828: Silence pytest.yield_fixture deprecation warning
Action: opened

PR body:
"""
pytest >= 2.10 supports yield based fixtures with pytest.fixture. In
pytest < 2.10 pytest.yield_fixture is required. But that function
also raises a deprecation warning in pytest >= 3.0. FreeIPA has to stay
compatible with pytest < 2.10 for RHEL 7 testing.

https://docs.pytest.org/en/latest/fixture.html#fixture-finalization-executing-teardown-code

https://pagure.io/freeipa/issue/6591

Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/828/head:pr828
git checkout pr828
From b48f676abc8af56d13c0c72a51aeb041ff421acf Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Mon, 29 May 2017 13:41:18 +0200
Subject: [PATCH] Silence pytest.yield_fixture deprecation warning

pytest >= 2.10 supports yield based fixtures with pytest.fixture. In
pytest < 2.10 pytest.yield_fixture is required. But that function
also raises a deprecation warning in pytest >= 3.0. FreeIPA has to stay
compatible with pytest < 2.10 for RHEL 7 testing.

https://docs.pytest.org/en/latest/fixture.html#fixture-finalization-executing-teardown-code

https://pagure.io/freeipa/issue/6591

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipatests/pytest_plugins/integration/__init__.py         |  5 +++--
 ipatests/test_ipaserver/test_kadmin.py                  |  3 ++-
 ipatests/test_util.py                                   | 11 +++++++++++
 ipatests/test_xmlrpc/test_host_plugin.py                |  5 +++--
 ipatests/test_xmlrpc/test_kerberos_principal_aliases.py |  5 +++--
 5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/ipatests/pytest_plugins/integration/__init__.py b/ipatests/pytest_plugins/integration/__init__.py
index 8fb10422e5..f1d8a0b91d 100644
--- a/ipatests/pytest_plugins/integration/__init__.py
+++ b/ipatests/pytest_plugins/integration/__init__.py
@@ -30,6 +30,7 @@
 
 from ipapython import ipautil
 from ipapython.ipa_log_manager import log_mgr
+from ipatests.test_util import yield_fixture
 from .config import Config
 from .env_config import get_global_config
 from . import tasks
@@ -143,7 +144,7 @@ def class_integration_logs():
     return {}
 
 
-@pytest.yield_fixture
+@yield_fixture
 def integration_logs(class_integration_logs, request):
     """Provides access to test integration logs, and collects after each test
     """
@@ -151,7 +152,7 @@ def integration_logs(class_integration_logs, request):
     collect_test_logs(request.node, class_integration_logs, request.config)
 
 
-@pytest.yield_fixture(scope='class')
+@yield_fixture(scope='class')
 def mh(request, class_integration_logs):
     """IPA's multihost fixture object
     """
diff --git a/ipatests/test_ipaserver/test_kadmin.py b/ipatests/test_ipaserver/test_kadmin.py
index 1b38791a11..2d4adfdeb7 100644
--- a/ipatests/test_ipaserver/test_kadmin.py
+++ b/ipatests/test_ipaserver/test_kadmin.py
@@ -13,9 +13,10 @@
 from ipalib import api
 
 from ipaserver.install import installutils
+from ipatests.test_util import yield_fixture
 
 
-@pytest.yield_fixture()
+@yield_fixture()
 def keytab():
     fd, keytab_path = tempfile.mkstemp(suffix='.keytab')
     os.close(fd)
diff --git a/ipatests/test_util.py b/ipatests/test_util.py
index f4e7773ca7..9720aee4ca 100644
--- a/ipatests/test_util.py
+++ b/ipatests/test_util.py
@@ -35,6 +35,17 @@
 pytestmark = pytest.mark.tier0
 
 
+# pytest >= 2.10 supports yield based fixtures with pytest.fixture. In
+# pytest < 2.10 pytest.yield_fixture is required. But that function
+# also raises a deprecation warning in pytest >= 3.0.
+PYTEST_VERSION = tuple(int(p) for p in pytest.__version__.split('.'))
+
+if PYTEST_VERSION < (2, 10):
+    yield_fixture = pytest.yield_fixture
+else:
+    yield_fixture = pytest.fixture
+
+
 class Prop(object):
     def __init__(self, *ops):
         self.__ops = frozenset(ops)
diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
index e4d6ee9635..eab5bf7b51 100644
--- a/ipatests/test_xmlrpc/test_host_plugin.py
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
@@ -34,6 +34,7 @@
 from ipalib import api, errors, x509
 from ipapython.dn import DN
 from ipapython.dnsutil import DNSName
+from ipatests.test_util import yield_fixture
 from ipatests.test_xmlrpc.xmlrpc_test import (XMLRPC_test,
     fuzzy_uuid, fuzzy_digits, fuzzy_hash, fuzzy_date, fuzzy_issuer,
     fuzzy_hex, raises_exact)
@@ -505,7 +506,7 @@ def test_try_validate_find(self, invalid_host):
         ), result)
 
 
-@pytest.yield_fixture
+@yield_fixture
 def keytabname(request):
     keytabfd, keytabname = tempfile.mkstemp()
     try:
@@ -589,7 +590,7 @@ def test_join_host(self, host, keytabname):
             command()
 
 
-@pytest.yield_fixture(scope='class')
+@yield_fixture(scope='class')
 def dns_setup(host):
     try:
         host.run_command('dnszone_del', dnszone, revzone, revipv6zone,
diff --git a/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py b/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py
index c94ff40434..9528992074 100644
--- a/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py
+++ b/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py
@@ -10,6 +10,7 @@
 from ipapython import ipautil
 from ipaplatform.paths import paths
 
+from ipatests.test_util import yield_fixture
 from ipatests.util import MockLDAP
 from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test
 from ipatests.test_xmlrpc.tracker.user_plugin import UserTracker
@@ -33,7 +34,7 @@
 )
 
 
-@pytest.yield_fixture
+@yield_fixture
 def trusted_domain():
     """Fixture providing mocked AD trust entries
 
@@ -51,7 +52,7 @@ def trusted_domain():
         ldap.del_entry(trusted_dom['dn'])
 
 
-@pytest.yield_fixture
+@yield_fixture
 def trusted_domain_with_suffix():
     """Fixture providing mocked AD trust entries
 
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to