Skip to content

Commit a17ad61

Browse files
committed
Add custom marker xp_extension()
1 parent d4467f1 commit a17ad61

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

conftest.py

+41-26
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
11
from hypothesis import settings
2+
from pytest import mark
3+
4+
5+
settings.register_profile('xp_default', deadline=800)
26

3-
# Add a --hypothesis-max-examples flag to pytest. See
4-
# https://github.com/HypothesisWorks/hypothesis/issues/2434#issuecomment-630309150
57

68
def pytest_addoption(parser):
7-
# Add an option to change the Hypothesis max_examples setting.
9+
# Enable extensions
810
parser.addoption(
9-
"--hypothesis-max-examples",
10-
"--max-examples",
11-
action="store",
11+
'--ext',
12+
'--extensions',
13+
nargs='+',
14+
default=[],
15+
help='enable testing for Array API extensions',
16+
)
17+
# Hypothesis max examples
18+
# See https://github.com/HypothesisWorks/hypothesis/issues/2434
19+
parser.addoption(
20+
'--hypothesis-max-examples',
21+
'--max-examples',
22+
action='store',
1223
default=None,
13-
help="set the Hypothesis max_examples setting",
24+
help='set the Hypothesis max_examples setting',
1425
)
15-
16-
# Add an option to disable the Hypothesis deadline
26+
# Hypothesis deadline
1727
parser.addoption(
18-
"--hypothesis-disable-deadline",
19-
"--disable-deadline",
20-
action="store_true",
21-
help="disable the Hypothesis deadline",
28+
'--hypothesis-disable-deadline',
29+
'--disable-deadline',
30+
action='store_true',
31+
help='disable the Hypothesis deadline',
2232
)
2333

2434

2535
def pytest_configure(config):
26-
# Set Hypothesis max_examples.
27-
hypothesis_max_examples = config.getoption("--hypothesis-max-examples")
36+
config.addinivalue_line(
37+
'markers', 'xp_extension(ext): tests an Array API extension'
38+
)
39+
# Configure Hypothesis
40+
hypothesis_max_examples = config.getoption('--hypothesis-max-examples')
2841
disable_deadline = config.getoption('--hypothesis-disable-deadline')
2942
profile_settings = {}
3043
if hypothesis_max_examples is not None:
3144
profile_settings['max_examples'] = int(hypothesis_max_examples)
3245
if disable_deadline is not None:
3346
profile_settings['deadline'] = None
3447
if profile_settings:
35-
import hypothesis
36-
37-
hypothesis.settings.register_profile(
38-
"array-api-tests-hypothesis-overridden", **profile_settings,
39-
)
40-
41-
hypothesis.settings.load_profile("array-api-tests-hypothesis-overridden")
42-
43-
44-
settings.register_profile('array_api_tests_hypothesis_profile', deadline=800)
45-
settings.load_profile('array_api_tests_hypothesis_profile')
48+
settings.register_profile('xp_override', **profile_settings)
49+
settings.load_profile('xp_override')
50+
else:
51+
settings.load_profile('xp_default')
52+
53+
54+
def pytest_collection_modifyitems(config, items):
55+
exts = config.getoption('--extensions')
56+
for item in items:
57+
if 'xp_extension' in item.keywords:
58+
ext = item.keywords['xp_extension'].args[0]
59+
if ext not in exts:
60+
item.add_marker(mark.skip(reason=f'{ext} not enabled in --extensions'))

0 commit comments

Comments
 (0)