Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
68 lines (54 loc) · 1.98 KB
/
Copy pathconftest.py
File metadata and controls
68 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import pytest
import xarray as xr
import xarray_validate as xv
# ------------------------------------------------------------------------------
# Pytest config
# ------------------------------------------------------------------------------
def pytest_addoption(parser):
"""Add custom command-line options."""
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
def pytest_configure(config):
"""Configure pytest based on command-line options."""
config.addinivalue_line(
"markers",
"slow: marks tests as slow (deselected by default, use --runslow to run)",
)
def pytest_collection_modifyitems(config, items):
"""Modify test collection based on command-line options."""
if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
# ------------------------------------------------------------------------------
# Fixtures
# ------------------------------------------------------------------------------
@pytest.fixture(autouse=True, scope="session")
def add_imports_to_xdoctest_namespace(xdoctest_namespace):
"""
Add common imports to the doctest namespace so that they are available
without explicit imports.
"""
xdoctest_namespace["np"] = np
xdoctest_namespace["xr"] = xr
xdoctest_namespace["xv"] = xv
@pytest.fixture
def ds():
"""
Test dataset fixture.
"""
ds = xr.Dataset(
{
"x": xr.DataArray(np.arange(4) - 2, dims="x"),
"foo": xr.DataArray(np.ones(4, dtype="i4"), dims="x"),
"bar": xr.DataArray(
np.arange(8, dtype=np.float64).reshape(4, 2), dims=("x", "y")
),
}
)
return ds