|
| 1 | +from hypothesis import settings |
| 2 | + |
| 3 | +# Add a --hypothesis-max-examples flag to pytest. See |
| 4 | +# https://github.com/HypothesisWorks/hypothesis/issues/2434#issuecomment-630309150 |
| 5 | + |
| 6 | +def pytest_addoption(parser): |
| 7 | + # Add an option to change the Hypothesis max_examples setting. |
| 8 | + parser.addoption( |
| 9 | + "--hypothesis-max-examples", |
| 10 | + "--max-examples", |
| 11 | + action="store", |
| 12 | + default=None, |
| 13 | + help="set the Hypothesis max_examples setting", |
| 14 | + ) |
| 15 | + |
| 16 | + # Add an option to disable the Hypothesis deadline |
| 17 | + parser.addoption( |
| 18 | + "--hypothesis-disable-deadline", |
| 19 | + "--disable-deadline", |
| 20 | + action="store_true", |
| 21 | + help="disable the Hypothesis deadline", |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +def pytest_configure(config): |
| 26 | + # Set Hypothesis max_examples. |
| 27 | + hypothesis_max_examples = config.getoption("--hypothesis-max-examples") |
| 28 | + disable_deadline = config.getoption('--hypothesis-disable-deadline') |
| 29 | + profile_settings = {} |
| 30 | + if hypothesis_max_examples is not None: |
| 31 | + profile_settings['max_examples'] = int(hypothesis_max_examples) |
| 32 | + if disable_deadline is not None: |
| 33 | + profile_settings['deadline'] = None |
| 34 | + 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') |
0 commit comments