Skip to content

Commit c52b3dd

Browse files
authored
Merge pull request #160 from boutproject/configure-installed-tests
Set options in conftest.py instead of pytest.ini, install conftest.py
2 parents 3b20d69 + dc41fee commit c52b3dd

File tree

4 files changed

+78
-34
lines changed

4 files changed

+78
-34
lines changed

conftest.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
import pytest
2-
3-
4-
# Add command line option '--long' for pytest, to be used to enable long tests
5-
def pytest_addoption(parser):
6-
parser.addoption(
7-
"--long",
8-
action="store_true",
9-
default=False,
10-
help="enable tests marked as 'long'",
11-
)
12-
13-
14-
def pytest_collection_modifyitems(config, items):
15-
if not config.getoption("--long"):
16-
# --long not given in cli: skip long tests
17-
print("\n skipping long tests, pass '--long' to enable")
18-
skip_long = pytest.mark.skip(reason="need --long option to run")
19-
for item in items:
20-
if "long" in item.keywords:
21-
item.add_marker(skip_long)
1+
from xbout.conftest import (
2+
pytest_configure,
3+
pytest_addoption,
4+
pytest_collection_modifyitems,
5+
)

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ calc =
5050
xhistogram
5151
docs = sphinx >= 1.4
5252

53-
[options.package_data]
54-
xbout = tests/pytest.ini
55-
5653
[build_sphinx]
5754
project = $metadata.name
5855
version = $metadata.version

xbout/conftest.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import pytest
2+
3+
4+
configure_is_imported = False
5+
6+
7+
def pytest_configure(config):
8+
global configure_is_imported
9+
if not configure_is_imported:
10+
configure_is_imported = True
11+
# filter expected warnings
12+
config.addinivalue_line(
13+
"filterwarnings",
14+
"ignore:No geometry type found, no coordinates will be added:UserWarning",
15+
)
16+
config.addinivalue_line(
17+
"filterwarnings",
18+
"ignore:deallocating CachingFileManager.*, but file is not already closed. "
19+
"This may indicate a bug.:RuntimeWarning",
20+
)
21+
22+
# register additional markers
23+
config.addinivalue_line(
24+
"markers",
25+
"long: long test, or one of many permutations (disabled by default)",
26+
)
27+
config.addinivalue_line(
28+
"markers",
29+
"flaky: xarray uses this mark, adding to avoid warnings about it not being "
30+
"defined",
31+
)
32+
config.addinivalue_line(
33+
"markers",
34+
"network: xarray uses this mark, adding to avoid warnings about it not "
35+
"being defined",
36+
)
37+
config.addinivalue_line(
38+
"markers",
39+
"slow: xarray uses this mark, adding to avoid warnings about it not being "
40+
"defined",
41+
)
42+
43+
44+
addoption_is_imported = False
45+
46+
47+
def pytest_addoption(parser):
48+
# Add command line option '--long' for pytest, to be used to enable long tests
49+
global addoption_is_imported
50+
if not addoption_is_imported:
51+
addoption_is_imported = True
52+
parser.addoption(
53+
"--long",
54+
action="store_true",
55+
default=False,
56+
help="enable tests marked as 'long'",
57+
)
58+
59+
60+
collection_is_imported = False
61+
62+
63+
def pytest_collection_modifyitems(config, items):
64+
global collection_is_imported
65+
if not collection_is_imported:
66+
collection_is_imported = True
67+
if not config.getoption("--long"):
68+
# --long not given in cli: skip long tests
69+
print("\n skipping long tests, pass '--long' to enable")
70+
skip_long = pytest.mark.skip(reason="need --long option to run")
71+
for item in items:
72+
if "long" in item.keywords:
73+
item.add_marker(skip_long)

xbout/tests/pytest.ini

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)