From 7edf2e20d4c898fbb637da3b3e6ded15808e040b Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Fri, 24 May 2019 22:01:31 -0400 Subject: [PATCH] Remove deprecated pytest.config usages (#2988) * initial attempt at moving away from deprecated pytest.config * whatsnew --- conftest.py | 20 ++++++++++++++++++++ doc/whats-new.rst | 2 ++ xarray/tests/__init__.py | 19 ++----------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/conftest.py b/conftest.py index d7f4e0c89bc..ffceb27e753 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,7 @@ """Configuration for pytest.""" +import pytest + def pytest_addoption(parser): """Add command-line flags for pytest.""" @@ -7,3 +9,21 @@ def pytest_addoption(parser): help="runs flaky tests") parser.addoption("--run-network-tests", action="store_true", help="runs tests requiring a network connection") + + +def pytest_collection_modifyitems(config, items): + + if not config.getoption("--run-flaky"): + skip_flaky = pytest.mark.skip( + reason="set --run-flaky option to run flaky tests") + for item in items: + if "flaky" in item.keywords: + item.add_marker(skip_flaky) + + if not config.getoption("--run-network-tests"): + skip_network = pytest.mark.skip( + reason="set --run-network-tests option to run tests requiring an" + "internet connection") + for item in items: + if "network" in item.keywords: + item.add_marker(skip_network) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index ab7c155950c..dfdca55d218 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -54,6 +54,8 @@ Bug fixes By `Deepak Cherian `_. +- Removed usages of `pytest.config`, which is deprecated (:issue:`2988`:) + By `Maximilian Roos `_. .. _whats-new.0.12.1: diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index e9d670e4dd9..5e559fce526 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -108,23 +108,8 @@ def LooseVersion(vstring): else: dask.config.set(scheduler='single-threaded') -# pytest config -try: - _SKIP_FLAKY = not pytest.config.getoption("--run-flaky") - _SKIP_NETWORK_TESTS = not pytest.config.getoption("--run-network-tests") -except (ValueError, AttributeError): - # Can't get config from pytest, e.g., because xarray is installed instead - # of being run from a development version (and hence conftests.py is not - # available). Don't run flaky tests. - _SKIP_FLAKY = True - _SKIP_NETWORK_TESTS = True - -flaky = pytest.mark.skipif( - _SKIP_FLAKY, reason="set --run-flaky option to run flaky tests") -network = pytest.mark.skipif( - _SKIP_NETWORK_TESTS, - reason="set --run-network-tests option to run tests requiring an " - "internet connection") +flaky = pytest.mark.flaky +network = pytest.mark.network @contextmanager