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

Fix the ability to run network and flaky tests #3070

Merged
merged 17 commits into from
Jul 4, 2019
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