diff --git a/hypothesis-python/src/hypothesis/stateful.py b/hypothesis-python/src/hypothesis/stateful.py index 5a9d44db1b..0e9706b285 100644 --- a/hypothesis-python/src/hypothesis/stateful.py +++ b/hypothesis-python/src/hypothesis/stateful.py @@ -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) @@ -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() @@ -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():