Skip to content

Commit 7ad4aba

Browse files
Fix Pytest4.1+ warnings about pytest.config
pytest.config global is deprecated since Pytest4.1: https://docs.pytest.org/en/latest/deprecations.html#pytest-config-global pytest-dev/pytest#3050 Fixes: https://pagure.io/freeipa/issue/7981 Co-authored-by: Christian Heimes <[email protected]> Signed-off-by: Stanislav Levin <[email protected]> Reviewed-By: Christian Heimes <[email protected]>
1 parent 910bdc4 commit 7ad4aba

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

ipatests/conftest.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from ipalib import api
1515
from ipalib.cli import cli_plugins
16+
import ipatests.util
1617

1718
try:
1819
import ipaplatform # pylint: disable=unused-import
@@ -91,6 +92,11 @@ def pytest_configure(config):
9192
# always run doc tests
9293
config.option.doctestmodules = True
9394

95+
# apply global options
96+
ipatests.util.SKIP_IPAAPI = config.option.skip_ipaapi
97+
ipatests.util.IPACLIENT_UNITTESTS = config.option.ipaclient_unittests
98+
ipatests.util.PRETTY_PRINT = config.option.pretty_print
99+
94100

95101
def pytest_addoption(parser):
96102
group = parser.getgroup("IPA integration tests")
@@ -147,11 +153,11 @@ def pytest_runtest_setup(item):
147153
get_marker = item.get_marker # pylint: disable=no-member
148154
if get_marker('skip_ipaclient_unittest'):
149155
# pylint: disable=no-member
150-
if pytest.config.option.ipaclient_unittests:
156+
if item.config.option.ipaclient_unittests:
151157
pytest.skip("Skip in ipaclient unittest mode")
152158
if get_marker('needs_ipaapi'):
153159
# pylint: disable=no-member
154-
if pytest.config.option.skip_ipaapi:
160+
if item.config.option.skip_ipaapi:
155161
pytest.skip("Skip tests that needs an IPA API")
156162
if get_marker('needs_install_package'):
157163
# pylint: disable=no-member

ipatests/test_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ def test_eq(self):
152152
assert (None == self.klass()) is True
153153

154154

155-
def test_assert_deepequal():
155+
def test_assert_deepequal(pytestconfig):
156156
f = util.assert_deepequal
157157
try: # pylint: disable=no-member
158-
pretty = pytest.config.getoption("pretty_print")
158+
pretty = pytestconfig.getoption("pretty_print")
159159
except (AttributeError, ValueError):
160160
pretty = False
161161

ipatests/util.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@
6767

6868
PYTEST_VERSION = tuple(int(v) for v in pytest.__version__.split('.'))
6969

70+
# settings are configured by conftest
71+
IPACLIENT_UNITTESTS = None
72+
SKIP_IPAAPI = None
73+
PRETTY_PRINT = None
74+
7075

7176
def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"):
7277
"""Call this in a package to skip the package in ipaclient-unittest mode
7378
"""
74-
config = pytest.config # pylint: disable=no-member
75-
if config.getoption('ipaclient_unittests', False):
79+
if IPACLIENT_UNITTESTS:
7680
if PYTEST_VERSION[0] >= 3:
7781
# pytest 3+ does no longer allow pytest.skip() on module level
7882
# pylint: disable=unexpected-keyword-arg
@@ -85,8 +89,7 @@ def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"):
8589
def check_no_ipaapi(reason="Skip tests that needs an IPA API"):
8690
"""Call this in a package to skip the package in no-ipaapi mode
8791
"""
88-
config = pytest.config # pylint: disable=no-member
89-
if config.getoption('skip_ipaapi', False):
92+
if SKIP_IPAAPI:
9093
if PYTEST_VERSION[0] >= 3:
9194
# pylint: disable=unexpected-keyword-arg
9295
raise pytest.skip.Exception(reason, allow_module_level=True)
@@ -384,12 +387,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
384387
Note that lists and tuples are considered equivalent, and the order of
385388
their elements does not matter.
386389
"""
387-
try:
388-
pretty_print = pytest.config.getoption("pretty_print")
389-
except (AttributeError, ValueError):
390-
pretty_print = False
391-
392-
if pretty_print:
390+
if PRETTY_PRINT:
393391
expected_str = struct_to_string(expected, EXPECTED_LEN)
394392
got_str = struct_to_string(got, GOT_LEN)
395393
else:

0 commit comments

Comments
 (0)