Skip to content

Commit 9457c1b

Browse files
committed
reduce more internal examples
1 parent e406b78 commit 9457c1b

File tree

1 file changed

+15
-5
lines changed
  • hypothesis-python/src/hypothesis/internal/conjecture

1 file changed

+15
-5
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/utils.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def sample(
173173
forced: Optional[int] = None,
174174
fake_forced: bool = False,
175175
) -> int:
176-
data.start_example(SAMPLE_IN_SAMPLER_LABEL)
176+
if self.observe:
177+
data.start_example(SAMPLE_IN_SAMPLER_LABEL)
177178
forced_choice = ( # pragma: no branch # https://github.com/nedbat/coveragepy/issues/1617
178179
None
179180
if forced is None
@@ -203,7 +204,8 @@ def sample(
203204
fake_forced=fake_forced,
204205
observe=self.observe,
205206
)
206-
data.stop_example()
207+
if self.observe:
208+
data.stop_example()
207209
if use_alternate:
208210
assert forced is None or alternate == forced, (forced, alternate)
209211
return alternate
@@ -254,15 +256,23 @@ def __init__(
254256
self.rejected = False
255257
self.observe = observe
256258

259+
def stop_example(self):
260+
if self.observe:
261+
self.data.stop_example()
262+
263+
def start_example(self, label):
264+
if self.observe:
265+
self.data.start_example(label)
266+
257267
def more(self) -> bool:
258268
"""Should I draw another element to add to the collection?"""
259269
if self.drawn:
260-
self.data.stop_example()
270+
self.stop_example()
261271

262272
self.drawn = True
263273
self.rejected = False
264274

265-
self.data.start_example(ONE_FROM_MANY_LABEL)
275+
self.start_example(ONE_FROM_MANY_LABEL)
266276
if self.min_size == self.max_size:
267277
# if we have to hit an exact size, draw unconditionally until that
268278
# point, and no further.
@@ -291,7 +301,7 @@ def more(self) -> bool:
291301
self.count += 1
292302
return True
293303
else:
294-
self.data.stop_example()
304+
self.stop_example()
295305
return False
296306

297307
def reject(self, why: Optional[str] = None) -> None:

0 commit comments

Comments
 (0)