Skip to content

Commit

Permalink
test: use pytest conftest.py and plugin to define hypothesis profile
Browse files Browse the repository at this point in the history
This seems to be the recommended way of defining hypothesis profiles.
  • Loading branch information
indygreg committed Oct 23, 2023
1 parent 1229817 commit 3fcb6a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ jobs:
- name: Test
run: |
pytest --numprocesses=auto -v tests/
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ jobs:
- name: Test C Backend
run: |
pytest --numprocesses=auto -v tests/
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/
- name: Test CFFI Backend
env:
PYTHON_ZSTANDARD_IMPORT_POLICY: 'cffi'
run: |
pytest --numprocesses=auto -v tests/
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/
- name: Test Rust Backend
if: matrix.arch == 'x64'
Expand All @@ -82,4 +82,4 @@ jobs:
env:
PYTHON_ZSTANDARD_IMPORT_POLICY: 'rust'
run: |
pytest --numprocesses=auto -v tests/
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/
20 changes: 0 additions & 20 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

from typing import List

try:
import hypothesis # type: ignore
except ImportError:
hypothesis = None # type: ignore


class NonClosingBytesIO(io.BytesIO):
"""BytesIO that saves the underlying buffer on close().
Expand Down Expand Up @@ -121,18 +116,3 @@ def generate_samples():
samples.append(inputs[-(i % 5)] * (i + 2))

return samples


if hypothesis:
default_settings = hypothesis.settings(deadline=10000)
hypothesis.settings.register_profile("default", default_settings)

ci_settings = hypothesis.settings(deadline=20000, max_examples=1000)
hypothesis.settings.register_profile("ci", ci_settings)

expensive_settings = hypothesis.settings(deadline=None, max_examples=10000)
hypothesis.settings.register_profile("expensive", expensive_settings)

hypothesis.settings.load_profile(
os.environ.get("HYPOTHESIS_PROFILE", "default")
)
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

try:
import hypothesis # type: ignore
except ImportError:
hypothesis = None # type: ignore


if hypothesis:
default_settings = hypothesis.settings(deadline=10000)
hypothesis.settings.register_profile("default", default_settings)

ci_settings = hypothesis.settings(deadline=20000, max_examples=1000)
hypothesis.settings.register_profile("ci", ci_settings)

expensive_settings = hypothesis.settings(deadline=None, max_examples=10000)
hypothesis.settings.register_profile("expensive", expensive_settings)

hypothesis.settings.load_profile(
os.environ.get("HYPOTHESIS_PROFILE", "default")
)

0 comments on commit 3fcb6a1

Please sign in to comment.