Skip to content

Commit 067fc76

Browse files
committed
Observe clearer status_reason
1 parent 2fda65f commit 067fc76

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

hypothesis-python/src/hypothesis/extra/array_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ def do_draw(self, data):
424424
while elements.more():
425425
i = data.draw_integer(0, self.array_size - 1)
426426
if i in assigned:
427-
elements.reject()
427+
elements.reject("chose an array index we've already used")
428428
continue
429429
val = data.draw(self.elements_strategy)
430430
if self.unique:
431431
if val in seen:
432-
elements.reject()
432+
elements.reject("chose an element we've already used")
433433
continue
434434
else:
435435
seen.add(val)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,13 +2273,13 @@ def _pop_ir_tree_node(self, ir_type: IRTypeName, kwargs: IRKWargsType) -> IRNode
22732273
# (in fact, it is possible that giving up early here results in more time
22742274
# for useful shrinks to run).
22752275
if node.ir_type != ir_type:
2276-
self.mark_invalid()
2276+
self.mark_invalid(f"(internal) want a {ir_type} but have a {node.ir_type}")
22772277

22782278
# if a node has different kwargs (and so is misaligned), but has a value
22792279
# that is allowed by the expected kwargs, then we can coerce this node
22802280
# into an aligned one by using its value. It's unclear how useful this is.
22812281
if not ir_value_permitted(node.value, node.ir_type, kwargs):
2282-
self.mark_invalid()
2282+
self.mark_invalid(f"(internal) got a {ir_type} but outside the valid range")
22832283

22842284
return node
22852285

@@ -2348,7 +2348,7 @@ def draw(
23482348
strategy.validate()
23492349

23502350
if strategy.is_empty:
2351-
self.mark_invalid("strategy is empty")
2351+
self.mark_invalid(f"empty strategy {self!r}")
23522352

23532353
if self.depth >= MAX_DEPTH:
23542354
self.mark_invalid("max depth exceeded")

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,15 @@ def generate_new_examples(self):
809809

810810
self.test_function(data)
811811

812+
if (
813+
data.status == Status.OVERRUN
814+
and max_length < BUFFER_SIZE
815+
and "invalid because" not in data.events
816+
):
817+
data.events["invalid because"] = (
818+
"reduced max size for early examples (avoids flaky health checks)"
819+
)
820+
812821
self.generate_mutations_from(data)
813822

814823
# Although the optimisations are logically a distinct phase, we

hypothesis-python/src/hypothesis/stateful.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def do_draw(self, data):
478478
machine = data.draw(self_strategy)
479479
bundle = machine.bundle(self.name)
480480
if not bundle:
481-
data.mark_invalid()
481+
data.mark_invalid(f"Cannot draw from empty bundle {self.name!r}")
482482
# Shrink towards the right rather than the left. This makes it easier
483483
# to delete data generated earlier, as when the error is towards the
484484
# end there can be a lot of hard to remove padding.

hypothesis-python/src/hypothesis/strategies/_internal/datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def do_draw(self, data):
155155

156156
# If we happened to end up with a disallowed imaginary time, reject it.
157157
if (not self.allow_imaginary) and datetime_does_not_exist(result):
158-
data.mark_invalid("nonexistent datetime")
158+
data.mark_invalid(f"{result} does not exist (usually a DST transition)")
159159
return result
160160

161161
def draw_naive_datetime_and_combine(self, data, tz):

0 commit comments

Comments
 (0)