Skip to content

Commit ef2b191

Browse files
committed
Defer types_with_core_strat until test runtime
1 parent 1f845e0 commit ef2b191

File tree

1 file changed

+44
-41
lines changed

1 file changed

+44
-41
lines changed

hypothesis-python/tests/cover/test_type_lookup.py

+44-41
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717
import pytest
1818

1919
from hypothesis import given, infer, settings, strategies as st
20-
from hypothesis.errors import (
21-
HypothesisDeprecationWarning,
22-
InvalidArgument,
23-
ResolutionFailed,
24-
)
20+
from hypothesis.errors import InvalidArgument, ResolutionFailed
2521
from hypothesis.internal.compat import get_type_hints
2622
from hypothesis.internal.reflection import get_pretty_function_description
2723
from hypothesis.strategies._internal import types
24+
from hypothesis.strategies._internal.lazy import LazyStrategy
2825
from hypothesis.strategies._internal.types import _global_type_lookup
2926
from hypothesis.strategies._internal.utils import _strategies
3027

@@ -36,42 +33,11 @@
3633
)
3734
from tests.common.utils import fails_with, temp_registered
3835

39-
# Build a set of all types output by core strategies
40-
blocklist = {
41-
"builds",
42-
"data",
43-
"deferred",
44-
"from_regex",
45-
"from_type",
46-
"ip_addresses",
47-
"iterables",
48-
"just",
49-
"nothing",
50-
"one_of",
51-
"permutations",
52-
"random_module",
53-
"randoms",
54-
"recursive",
55-
"runner",
56-
"sampled_from",
57-
"shared",
58-
"timezone_keys",
59-
"timezones",
36+
types_with_core_strat = {
37+
type_
38+
for type_, strat in _global_type_lookup.items()
39+
if isinstance(strat, LazyStrategy) and strat.function in vars(st).values()
6040
}
61-
assert set(_strategies).issuperset(blocklist), blocklist.difference(_strategies)
62-
types_with_core_strat = set()
63-
for thing in (
64-
getattr(st, name)
65-
for name in sorted(_strategies)
66-
if name in dir(st) and name not in blocklist
67-
):
68-
for n in range(3):
69-
try:
70-
ex = find_any(thing(*([st.nothing()] * n)))
71-
types_with_core_strat.add(type(ex))
72-
break
73-
except (TypeError, InvalidArgument, HypothesisDeprecationWarning):
74-
continue
7541

7642

7743
@pytest.mark.skipif(sys.version_info[:2] >= (3, 14), reason="FIXME-py314")
@@ -91,7 +57,44 @@ def inner(ex):
9157

9258

9359
def test_lookup_knows_about_all_core_strategies():
94-
cannot_lookup = types_with_core_strat - set(types._global_type_lookup)
60+
# Build a set of all types output by core strategies
61+
blocklist = {
62+
"builds",
63+
"data",
64+
"deferred",
65+
"from_regex",
66+
"from_type",
67+
"ip_addresses",
68+
"iterables",
69+
"just",
70+
"nothing",
71+
"one_of",
72+
"permutations",
73+
"random_module",
74+
"randoms",
75+
"recursive",
76+
"runner",
77+
"sampled_from",
78+
"shared",
79+
"timezone_keys",
80+
"timezones",
81+
}
82+
assert set(_strategies).issuperset(blocklist), blocklist.difference(_strategies)
83+
found = set()
84+
for thing in (
85+
getattr(st, name)
86+
for name in sorted(_strategies)
87+
if name in dir(st) and name not in blocklist
88+
):
89+
for n in range(3):
90+
try:
91+
ex = find_any(thing(*([st.nothing()] * n)))
92+
found.add(type(ex))
93+
break
94+
except Exception:
95+
continue
96+
97+
cannot_lookup = found - set(types._global_type_lookup)
9598
assert not cannot_lookup
9699

97100

0 commit comments

Comments
 (0)