Skip to content

Commit 7b77c6f

Browse files
authored
hypothesis tweaks (#321)
* url tests for hypothesis and faster hypothesis by default * tweak hypothesis settings * uprev hypothesis * hypothesis seems to get flakey with more test cases :-(
1 parent 5ab2762 commit 7b77c6f

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
- run: make test
8686
env:
8787
BENCHMARK_VS_PYDANTIC: 1
88+
HYPOTHESIS_PROFILE: slow
8889

8990
- run: ls -lha
9091
- run: coverage xml

tests/conftest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
from pathlib import Path
1010
from typing import Any, Type
1111

12+
import hypothesis
1213
import pytest
13-
from hypothesis import settings
1414
from typing_extensions import Literal
1515

1616
from pydantic_core import SchemaValidator
1717

1818
__all__ = 'Err', 'PyAndJson', 'plain_repr', 'infinite_generator'
1919

20-
hyp_max_examples = os.getenv('HYPOTHESIS_MAX_EXAMPLES')
21-
if hyp_max_examples:
22-
settings.register_profile('custom', max_examples=int(hyp_max_examples))
23-
settings.load_profile('custom')
20+
hypothesis.settings.register_profile('fast', max_examples=2)
21+
hypothesis.settings.register_profile('slow', max_examples=1_000)
22+
hypothesis.settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'fast'))
2423

2524

2625
def plain_repr(obj):

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
coverage==6.4.1
22
dirty-equals==0.4
3-
hypothesis==6.48.1
3+
hypothesis==6.56.4
44
pytest==7.1.2
55
pytest-benchmark==3.4.1
66
pytest-mock==3.8.1

tests/test_hypothesis.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,19 @@ def test_pytimedelta_as_timedelta(dt):
131131
total_seconds = (1 if pos == 'true' else -1) * (int(day) * 86_400 + int(sec) + int(micro) / 1_000_000)
132132

133133
assert total_seconds == pytest.approx(dt.total_seconds())
134+
135+
136+
@pytest.fixture(scope='module')
137+
def url_validator():
138+
return SchemaValidator({'type': 'url'})
139+
140+
141+
@given(strategies.text())
142+
def test_urls_text(url_validator, text):
143+
try:
144+
url_validator.validate_python(text)
145+
except ValidationError as exc:
146+
assert exc.error_count() == 1
147+
error = exc.errors()[0]
148+
assert error['type'] == 'url_error'
149+
assert error['ctx']['error'] == 'relative URL without a base'

0 commit comments

Comments
 (0)