From 8c0192ac3de157ec4ef17c5492bfcb2fe370ac46 Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Apr 22 2020 08:01:25 +0000 Subject: ipatests: Remove deprecated yield_fixture 'yield_fixture' is deprecated since Pytest3 [0]. FreeIPA requires at least 3.9.1. So, it can be safely removed. [0]: https://docs.pytest.org/en/latest/yieldfixture.html Fixes: https://pagure.io/freeipa/issue/8101 Signed-off-by: Stanislav Levin Reviewed-By: Sergey Orlov --- diff --git a/ipatests/pytest_ipa/integration/__init__.py b/ipatests/pytest_ipa/integration/__init__.py index 80cbd83..f7a31c8 100644 --- a/ipatests/pytest_ipa/integration/__init__.py +++ b/ipatests/pytest_ipa/integration/__init__.py @@ -32,7 +32,6 @@ from pytest_multihost import make_multihost_fixture from ipapython import ipautil from ipaplatform.paths import paths -from ipatests.test_util import yield_fixture from .config import Config from .env_config import get_global_config from . import tasks @@ -187,7 +186,7 @@ def class_integration_logs(): return {} -@yield_fixture +@pytest.fixture def integration_logs(class_integration_logs, request): """Provides access to test integration logs, and collects after each test """ @@ -197,7 +196,7 @@ def integration_logs(class_integration_logs, request): collect_systemd_journal(request.node, hosts, request.config) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def mh(request, class_integration_logs): """IPA's multihost fixture object """ diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py index f0b08f0..f13dfb5 100644 --- a/ipatests/test_integration/test_backup_and_restore.py +++ b/ipatests/test_integration/test_backup_and_restore.py @@ -162,7 +162,7 @@ def restore_checker(host): assert_func(expected, got) -@pytest.yield_fixture(scope="function") +@pytest.fixture def cert_sign_request(request): master = request.instance.master hosts = [master] + request.instance.replicas diff --git a/ipatests/test_integration/test_smb.py b/ipatests/test_integration/test_smb.py index 2cc9c4f..d3d6272 100644 --- a/ipatests/test_integration/test_smb.py +++ b/ipatests/test_integration/test_smb.py @@ -75,7 +75,7 @@ class TestSMB(IntegrationTest): for user in [cls.ipa_user1, cls.ipa_user2, cls.ad_user]: tasks.run_command_as_user(cls.smbserver, user, ['stat', '.']) - @pytest.yield_fixture + @pytest.fixture def enable_smb_client_dns_lookup_kdc(self): smbclient = self.smbclient with tasks.FileBackup(smbclient, paths.KRB5_CONF): @@ -86,7 +86,7 @@ class TestSMB(IntegrationTest): smbclient.put_file_contents(paths.KRB5_CONF, krb5_conf) yield - @pytest.yield_fixture + @pytest.fixture def samba_share_public(self): """Setup share outside /home on samba server.""" share_name = 'shared' diff --git a/ipatests/test_ipaserver/test_kadmin.py b/ipatests/test_ipaserver/test_kadmin.py index 9f3e980..5ef565c 100644 --- a/ipatests/test_ipaserver/test_kadmin.py +++ b/ipatests/test_ipaserver/test_kadmin.py @@ -13,10 +13,9 @@ import tempfile from ipalib import api from ipaserver.install import installutils -from ipatests.test_util import yield_fixture -@yield_fixture() +@pytest.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 2d93df6..d4b6250 100644 --- a/ipatests/test_util.py +++ b/ipatests/test_util.py @@ -33,19 +33,6 @@ if six.PY3: unicode = str 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 - - pattern_type = type(re.compile("")) diff --git a/ipatests/test_xmlrpc/test_cert_request_ip_address.py b/ipatests/test_xmlrpc/test_cert_request_ip_address.py index 3e9af41..bf4de05 100644 --- a/ipatests/test_xmlrpc/test_cert_request_ip_address.py +++ b/ipatests/test_xmlrpc/test_cert_request_ip_address.py @@ -24,7 +24,6 @@ from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.x509.oid import NameOID from ipalib import api, errors -from ipatests.test_util import yield_fixture from ipatests.test_xmlrpc.tracker.host_plugin import HostTracker from ipatests.test_xmlrpc.tracker.user_plugin import UserTracker from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test @@ -79,41 +78,41 @@ def _record_setup(host, zone, record, **kwargs): host.run_command('dnsrecord_del', zone, record, **kwargs) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv4_revzone(host): yield from _zone_setup(host, ipv4_revzone_s) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv6_revzone(host): yield from _zone_setup(host, ipv6_revzone_s) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv4_ptr(host, ipv4_revzone): yield from _record_setup( host, ipv4_revzone, ipv4_revrec_s, ptrrecord=host_ptr) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv6_ptr(host, ipv6_revzone): yield from _record_setup( host, ipv6_revzone, ipv6_revrec_s, ptrrecord=host_ptr) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv4_a(host): yield from _record_setup( host, api.env.domain, 'iptest', arecord=ipv4_address) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def ipv6_aaaa(host): yield from _record_setup( host, api.env.domain, 'iptest', aaaarecord=ipv6_address) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def other_forward_records(host): """ Create A and AAAA records (to the "correct" IP address) for @@ -125,19 +124,19 @@ def other_forward_records(host): arecord=ipv4_address, aaaarecord=ipv6_address) -@yield_fixture(scope='function') +@pytest.fixture(scope='function') def ipv4_ptr_other(host, ipv4_revzone): yield from _record_setup( host, ipv4_revzone, ipv4_revrec_s, ptrrecord=other_ptr) -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def cname1(host): yield from _record_setup( host, api.env.domain, 'cname1', cnamerecord='iptest') -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def cname2(host): yield from _record_setup( host, api.env.domain, 'cname2', cnamerecord='cname1') diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py index 910fb8d..9e65905 100644 --- a/ipatests/test_xmlrpc/test_host_plugin.py +++ b/ipatests/test_xmlrpc/test_host_plugin.py @@ -36,7 +36,6 @@ from ipaplatform.paths import paths from ipapython import ipautil from ipapython.dn import DN from ipapython.dnsutil import DNSName -from ipatests.test_util import yield_fixture from ipatests.test_xmlrpc import objectclasses from ipatests.test_xmlrpc.test_user_plugin import get_group_dn from ipatests.test_xmlrpc.testcert import get_testcert, subject_base @@ -643,7 +642,7 @@ class TestValidation(XMLRPC_test): ), result) -@yield_fixture +@pytest.fixture def keytabname(request): keytabfd, keytabname = tempfile.mkstemp() try: @@ -727,7 +726,7 @@ class TestHostFalsePwdChange(XMLRPC_test): command() -@yield_fixture(scope='class') +@pytest.fixture(scope='class') def dns_setup_nonameserver(host4): # Make sure that the server does not handle the reverse zone used # for the test @@ -819,7 +818,7 @@ class TestHostNoNameserversForRevZone(XMLRPC_test): pass -@yield_fixture(scope='class') +@pytest.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 30d57e6..61d3684 100644 --- a/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py +++ b/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py @@ -12,7 +12,6 @@ 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 @@ -51,7 +50,7 @@ TRACKER_DATA = [ ] -@yield_fixture +@pytest.fixture def trusted_domain(): """Fixture providing mocked AD trust entries @@ -69,7 +68,7 @@ def trusted_domain(): ldap.del_entry(trusted_dom['dn']) -@yield_fixture +@pytest.fixture def trusted_domain_with_suffix(): """Fixture providing mocked AD trust entries