@@ -122,11 +122,7 @@ def run_state_machine(factory, data):
122
122
try :
123
123
if print_steps :
124
124
report (f"state = { machine .__class__ .__name__ } ()" )
125
- try :
126
- machine .check_invariants (settings )
127
- finally :
128
- if print_steps :
129
- machine ._print_invariants ()
125
+ machine .check_invariants (settings )
130
126
max_steps = settings .stateful_step_count
131
127
steps_run = 0
132
128
@@ -208,11 +204,7 @@ def run_state_machine(factory, data):
208
204
# If it does, and the result is a 'MultipleResult',
209
205
# then 'print_step' prints a multi-variable assignment.
210
206
machine ._print_step (rule , data_to_print , result )
211
- try :
212
- machine .check_invariants (settings )
213
- finally :
214
- if print_steps :
215
- machine ._print_invariants ()
207
+ machine .check_invariants (settings )
216
208
cd .stop_example ()
217
209
finally :
218
210
if print_steps :
@@ -364,15 +356,6 @@ def _print_step(self, rule, data, result):
364
356
)
365
357
)
366
358
367
- def _print_invariants (self ):
368
- for invar in self .invariants ():
369
- if self ._initialize_rules_to_run and not invar .check_during_init :
370
- continue
371
- if not all (precond (self ) for precond in invar .preconditions ):
372
- continue
373
- report ("state.{}()" .format (invar .function .__name__ )
374
- )
375
-
376
359
def _add_result_to_targets (self , targets , result ):
377
360
name = self ._new_name ()
378
361
self .__printer .singleton_pprinters .setdefault (
@@ -388,6 +371,11 @@ def check_invariants(self, settings):
388
371
continue
389
372
if not all (precond (self ) for precond in invar .preconditions ):
390
373
continue
374
+ if (
375
+ current_build_context ().is_final
376
+ or settings .verbosity >= Verbosity .debug
377
+ ):
378
+ report (f"state.{ invar .function .__name__ } ()" )
391
379
result = invar .function (self )
392
380
if result is not None :
393
381
fail_health_check (
0 commit comments