Skip to content

Commit

Permalink
Better status_reason obs on abort
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 24, 2024
1 parent 3ae6e44 commit efd38d0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions hypothesis-python/src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def runTest(self):
return StateMachineTestCase


@attr.s()
@attr.s(repr=False)
class Rule:
targets = attr.ib()
function = attr.ib(repr=get_pretty_function_description)
Expand All @@ -451,6 +451,11 @@ def __attrs_post_init__(self):
self.arguments_strategies[k] = v
self.bundles = tuple(bundles)

def __repr__(self) -> str:
rep = get_pretty_function_description
bits = [f"{k}={rep(v)}" for k, v in attr.asdict(self).items() if v]
return f"{self.__class__.__name__}({', '.join(bits)})"


self_strategy = st.runner()

Expand Down Expand Up @@ -966,17 +971,16 @@ def do_draw(self, data):

feature_flags = data.draw(self.enabled_rules_strategy)

# Note: The order of the filters here is actually quite important,
# because checking is_enabled makes choices, so increases the size of
# the choice sequence. This means that if we are in a case where many
# rules are invalid we will make a lot more choices if we ask if they
# are enabled before we ask if they are valid, so our test cases will
# be artificially large.
rule = data.draw(
st.sampled_from(self.rules)
.filter(self.is_valid)
.filter(lambda r: feature_flags.is_enabled(r.function.__name__))
)
def rule_is_enabled(r):
# Note: The order of the filters here is actually quite important,
# because checking is_enabled makes choices, so increases the size of
# the choice sequence. This means that if we are in a case where many
# rules are invalid we would make a lot more choices if we ask if they
# are enabled before we ask if they are valid, so our test cases would
# be artificially large.
return self.is_valid(r) and feature_flags.is_enabled(r.function.__name__)

rule = data.draw(st.sampled_from(self.rules).filter(rule_is_enabled))

arguments = {}
for k, strat in rule.arguments_strategies.items():
Expand Down

0 comments on commit efd38d0

Please sign in to comment.