File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ RELEASE_TYPE: patch
2+
3+ This patch supports assigning ``settings = settings(...) `` as a class attribute
4+ on a subclass of a ``.TestCase `` attribute of a :class: `~hypothesis.stateful.RuleBasedStateMachine `.
5+ Previously, this did nothing at all.
6+
7+ .. code-block: python
8+
9+ # works as of this release
10+ class TestMyStatefulMachine(MyStatefulMachine.TestCase):
11+ settings = settings(max_examples=10000)
12+
13+ # the old way still works, but it's more verbose.
14+ MyStateMachine.TestCase.settings = settings(max_examples=10000)
15+ class TestMyStatefulMachine(MyStatefulMachine.TestCase):
16+ pass
17+
18+ Thanks to Joey Tran for reporting these settings-related edge cases in stateful testing.
Original file line number Diff line number Diff line change @@ -402,7 +402,7 @@ class StateMachineTestCase(TestCase):
402402 settings = Settings (deadline = None , suppress_health_check = list (HealthCheck ))
403403
404404 def runTest (self ):
405- run_state_machine_as_test (cls )
405+ run_state_machine_as_test (cls , settings = self . settings )
406406
407407 runTest .is_hypothesis_test = True
408408
Original file line number Diff line number Diff line change @@ -186,3 +186,18 @@ def test_bad_machines_fail(machine):
186186 notes = err .__notes__
187187 steps = [l for l in notes if "Step " in l or "state." in l ]
188188 assert 1 <= len (steps ) <= 50
189+
190+
191+ class MyStatefulMachine (RuleBasedStateMachine ):
192+ def __init__ (self ):
193+ self .n_steps = 0
194+ super ().__init__ ()
195+
196+ @rule ()
197+ def step (self ):
198+ self .n_steps += 1
199+ assert self .n_steps <= 10
200+
201+
202+ class TestMyStatefulMachine (MyStatefulMachine .TestCase ):
203+ settings = Settings (derandomize = True , stateful_step_count = 5 )
You can’t perform that action at this time.
0 commit comments