Skip to content

Commit

Permalink
Fix Pytest4.1+ warnings about pytest.config
Browse files Browse the repository at this point in the history
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 <cheimes@redhat.com>

Signed-off-by: Stanislav Levin <slev@altlinux.org>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
stanislavlevin committed Jul 15, 2019
1 parent 2d08102 commit bd2d823
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 8 additions & 2 deletions ipatests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ipalib import api
from ipalib.cli import cli_plugins
import ipatests.util

try:
import ipaplatform # pylint: disable=unused-import
Expand Down Expand Up @@ -91,6 +92,11 @@ def pytest_configure(config):
# always run doc tests
config.option.doctestmodules = True

# apply global options
ipatests.util.SKIP_IPAAPI = config.option.skip_ipaapi
ipatests.util.IPACLIENT_UNITTESTS = config.option.ipaclient_unittests
ipatests.util.PRETTY_PRINT = config.option.pretty_print


def pytest_addoption(parser):
group = parser.getgroup("IPA integration tests")
Expand Down Expand Up @@ -147,11 +153,11 @@ def pytest_runtest_setup(item):
get_marker = item.get_marker # pylint: disable=no-member
if get_marker('skip_ipaclient_unittest'):
# pylint: disable=no-member
if pytest.config.option.ipaclient_unittests:
if item.config.option.ipaclient_unittests:
pytest.skip("Skip in ipaclient unittest mode")
if get_marker('needs_ipaapi'):
# pylint: disable=no-member
if pytest.config.option.skip_ipaapi:
if item.config.option.skip_ipaapi:
pytest.skip("Skip tests that needs an IPA API")
if get_marker('needs_install_package'):
# pylint: disable=no-member
Expand Down
4 changes: 2 additions & 2 deletions ipatests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def test_eq(self):
assert (None == self.klass()) is True


def test_assert_deepequal():
def test_assert_deepequal(pytestconfig):
f = util.assert_deepequal
try: # pylint: disable=no-member
pretty = pytest.config.getoption("pretty_print")
pretty = pytestconfig.getoption("pretty_print")
except (AttributeError, ValueError):
pretty = False

Expand Down
18 changes: 8 additions & 10 deletions ipatests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@

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

# settings are configured by conftest
IPACLIENT_UNITTESTS = None
SKIP_IPAAPI = None
PRETTY_PRINT = None


def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"):
"""Call this in a package to skip the package in ipaclient-unittest mode
"""
config = pytest.config # pylint: disable=no-member
if config.getoption('ipaclient_unittests', False):
if IPACLIENT_UNITTESTS:
if PYTEST_VERSION[0] >= 3:
# pytest 3+ does no longer allow pytest.skip() on module level
# pylint: disable=unexpected-keyword-arg
Expand All @@ -85,8 +89,7 @@ def check_ipaclient_unittests(reason="Skip in ipaclient unittest mode"):
def check_no_ipaapi(reason="Skip tests that needs an IPA API"):
"""Call this in a package to skip the package in no-ipaapi mode
"""
config = pytest.config # pylint: disable=no-member
if config.getoption('skip_ipaapi', False):
if SKIP_IPAAPI:
if PYTEST_VERSION[0] >= 3:
# pylint: disable=unexpected-keyword-arg
raise pytest.skip.Exception(reason, allow_module_level=True)
Expand Down Expand Up @@ -384,12 +387,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
Note that lists and tuples are considered equivalent, and the order of
their elements does not matter.
"""
try:
pretty_print = pytest.config.getoption("pretty_print")
except (AttributeError, ValueError):
pretty_print = False

if pretty_print:
if PRETTY_PRINT:
expected_str = struct_to_string(expected, EXPECTED_LEN)
got_str = struct_to_string(got, GOT_LEN)
else:
Expand Down

0 comments on commit bd2d823

Please sign in to comment.