Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Remove deprecated pytest.config usages (pydata#2988)
Browse files Browse the repository at this point in the history
* initial attempt at moving away from deprecated pytest.config

* whatsnew
  • Loading branch information
max-sixty authored May 25, 2019
1 parent 0811141 commit 7edf2e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
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

0 comments on commit 7edf2e2

Please sign in to comment.