Skip to content

Commit

Permalink
Fix Pytest4.1+ warnings about pytest.config
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislavlevin committed Jun 17, 2019
1 parent 02d6fc7 commit f2d6532
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ipatests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def pytest_configure(config):

# always run doc tests
config.option.doctestmodules = True
# pytest.config global is deprecated
pytest.ipa_pytestconfig = config


def pytest_addoption(parser):
Expand Down Expand Up @@ -135,11 +137,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")


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
6 changes: 3 additions & 3 deletions ipatests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
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
config = pytest.ipa_pytestconfig # pylint: disable=no-member
if config.getoption('ipaclient_unittests', False):
if PYTEST_VERSION[0] >= 3:
# pytest 3+ does no longer allow pytest.skip() on module level
Expand All @@ -89,7 +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
config = pytest.ipa_pytestconfig # pylint: disable=no-member
if config.getoption('skip_ipaapi', False):
if PYTEST_VERSION[0] >= 3:
# pylint: disable=unexpected-keyword-arg
Expand Down Expand Up @@ -389,7 +389,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
their elements does not matter.
"""
try:
pretty_print = pytest.config.getoption("pretty_print")
pretty_print = pytest.ipa_pytestconfig.getoption("pretty_print")
except (AttributeError, ValueError):
pretty_print = False

Expand Down

0 comments on commit f2d6532

Please sign in to comment.