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

Commit

Permalink
Fix the ability to run network and flaky tests (pydata#3070)
Browse files Browse the repository at this point in the history
* Fix the ability to run network and flaky tests

The old setup didn't seem to work on CI, even when we explicitly passed the
relevant flags.

* fix flake8

* verbose tests

* Fix use of pytest_extra_flags

* Update conda

* add --yes

* fix allowed failure

* fixup allow failures

* Update conda in base

* Don't update conda

* Tweak conditional

* Fix pandas.Panel fix

* Try an alternative for allowed failures

* exit

* tweak exit

* fix bash
  • Loading branch information
shoyer authored Jul 4, 2019
1 parent 0e0d42c commit 1a5b630
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
1 change: 0 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
pytest_extra_flags: --run-flaky --run-network-tests
allow_failure: true
# TODO: add numpy-dev to the test-matrix
continueOnError: ${{ variables['allow_failure'] }}
pool:
vmImage: 'ubuntu-16.04'
steps:
Expand Down
19 changes: 8 additions & 11 deletions ci/azure/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ steps:
python -OO -c "import xarray"
displayName: Import xarray

# Work around for allowed test failures:
# https://github.com/microsoft/azure-pipelines-tasks/issues/9302
- bash: |
source activate test_env
pytest xarray --junitxml=junit/test-results.xml \
pytest xarray \
--test-run-title="$(conda_env) $(pytest_extra_flags)" \
--junitxml=junit/test-results.xml \
--cov=xarray --cov-config=ci/.coveragerc --cov-report=xml \
--cov-report=html $EXTRA_FLAGS
$(pytest_extra_flags) || [ "$ALLOW_FAILURE" = "true" ]
displayName: Run tests

- bash: |
bash <(curl https://codecov.io/bash) -t 688f4d53-31bb-49b5-8370-4ce6f792cf3d
displayName: Upload coverage to codecov.io

# TODO: publish coverage results to Azure, once we can merge them across
# multiple jobs: https://stackoverflow.com/questions/56776185

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-*.xml'
failTaskOnFailedTests: true
testRunTitle: 'Test results for Python $(conda_env) $(pytest_extra_flags)'
# TODO: publish coverage results to Azure, once we can merge them across
# multiple jobs: https://stackoverflow.com/questions/56776185
24 changes: 8 additions & 16 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ def pytest_addoption(parser):
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)
def pytest_runtest_setup(item):
# based on https://stackoverflow.com/questions/47559524
if 'flaky' in item.keywords and not item.config.getoption("--run-flaky"):
pytest.skip("set --run-flaky option to run flaky tests")
if ('network' in item.keywords
and not item.config.getoption("--run-network-tests")):
pytest.skip("set --run-network-tests to run test requiring an "
"internet connection")
4 changes: 2 additions & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_constructor_from_self_described(self):
actual = DataArray(series)
assert_equal(expected[0].reset_coords('x', drop=True), actual)

if hasattr(pd, 'Panel'):
if LooseVersion(pd.__version__) < '0.25.0':
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'\W*Panel is deprecated')
panel = pd.Panel({0: frame})
Expand Down Expand Up @@ -2971,7 +2971,7 @@ def test_to_pandas(self):

# roundtrips
for shape in [(3,), (3, 4), (3, 4, 5)]:
if len(shape) > 2 and not hasattr(pd, 'Panel'):
if len(shape) > 2 and not LooseVersion(pd.__version__) < '0.25.0':
continue
dims = list('abc')[:len(shape)]
da = DataArray(np.random.randn(*shape), dims=dims)
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from xarray.core.pycompat import integer_types

from . import (
InaccessibleArray, UnexpectedDataAccess, assert_allclose,
LooseVersion, InaccessibleArray, UnexpectedDataAccess, assert_allclose,
assert_array_equal, assert_equal, assert_identical, has_cftime, has_dask,
raises_regex, requires_bottleneck, requires_cftime, requires_dask,
requires_numbagg, requires_scipy, source_ndarray)
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_constructor_pandas_single(self):
DataArray(np.random.rand(4, 3), dims=['a', 'b']), # df
]

if hasattr(pd, 'Panel'):
if LooseVersion(pd.__version__) < '0.25.0':
das.append(
DataArray(np.random.rand(4, 3, 2), dims=['a', 'b', 'c']))

Expand Down

0 comments on commit 1a5b630

Please sign in to comment.