|
1 | 1 | from hypothesis import settings
|
| 2 | +from pytest import mark |
| 3 | + |
| 4 | + |
| 5 | +settings.register_profile('xp_default', deadline=800) |
2 | 6 |
|
3 |
| -# Add a --hypothesis-max-examples flag to pytest. See |
4 |
| -# https://github.com/HypothesisWorks/hypothesis/issues/2434#issuecomment-630309150 |
5 | 7 |
|
6 | 8 | def pytest_addoption(parser):
|
7 |
| - # Add an option to change the Hypothesis max_examples setting. |
| 9 | + # Enable extensions |
8 | 10 | 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', |
12 | 23 | default=None,
|
13 |
| - help="set the Hypothesis max_examples setting", |
| 24 | + help='set the Hypothesis max_examples setting', |
14 | 25 | )
|
15 |
| - |
16 |
| - # Add an option to disable the Hypothesis deadline |
| 26 | + # Hypothesis deadline |
17 | 27 | 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', |
22 | 32 | )
|
23 | 33 |
|
24 | 34 |
|
25 | 35 | 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') |
28 | 41 | disable_deadline = config.getoption('--hypothesis-disable-deadline')
|
29 | 42 | profile_settings = {}
|
30 | 43 | if hypothesis_max_examples is not None:
|
31 | 44 | profile_settings['max_examples'] = int(hypothesis_max_examples)
|
32 | 45 | if disable_deadline is not None:
|
33 | 46 | profile_settings['deadline'] = None
|
34 | 47 | 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