Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated pytest.config usages #2988

Merged
merged 2 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
"""Configuration for pytest."""

import pytest


def pytest_addoption(parser):
"""Add command-line flags for pytest."""
parser.addoption("--run-flaky", action="store_true",
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)
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Bug fixes
By `Deepak Cherian <https://github.com/dcherian`_.
- A deep copy deep-copies the coords (:issue:`1463`)
By `Martin Pletcher <https://github.com/pletchm>`_.
- Removed usages of `pytest.config`, which is deprecated (:issue:`2988`:)
By `Maximilian Roos <https://github.com/max-sixty>`_.

.. _whats-new.0.12.1:

Expand Down
19 changes: 2 additions & 17 deletions xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down