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 <cheimes@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Christian Heimes 2017-05-29 13:41:18 +02:00 committed by Martin Basti
parent f960450820
commit af140b0bc1
5 changed files with 22 additions and 7 deletions

View File

@ -30,6 +30,7 @@ from pytest_multihost import make_multihost_fixture
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
"""

View File

@ -13,9 +13,10 @@ import tempfile
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)

View File

@ -35,6 +35,17 @@ if six.PY3:
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)

View File

@ -34,6 +34,7 @@ from ipapython import ipautil
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 @@ class TestValidation(XMLRPC_test):
), result)
@pytest.yield_fixture
@yield_fixture
def keytabname(request):
keytabfd, keytabname = tempfile.mkstemp()
try:
@ -589,7 +590,7 @@ class TestHostFalsePwdChange(XMLRPC_test):
command()
@pytest.yield_fixture(scope='class')
@yield_fixture(scope='class')
def dns_setup(host):
try:
host.run_command('dnszone_del', dnszone, revzone, revipv6zone,

View File

@ -10,6 +10,7 @@ from ipalib import errors, api
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 @@ TRUSTED_DOMAIN_MOCK['ldif'] = get_trusted_dom_dict(
)
@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