1

When using the hypothesis library and performing stateful testing, how can I see or output the Bundle "services" the library is trying on my code?

Example

import hypothesis.strategies as st
from hypothesis.strategies import integers
from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule, precondition

class test_servicediscovery(RuleBasedStateMachine):
    services = Bundle('services')    
    @rule(target=services, s=st.integers(min_value=0, max_value=2)) 
    def add_service(self, s):
        return s

The question is: how do I print / see the Bundle "services" variable, generated by the library?

Aniket
  • 11
  • 4

1 Answers1

0

In the example you've given, the services bundle isn't being tried on your code - you're adding things to it, but never using them as inputs to another rule.

If you are, running Hypothesis in verbose mode will show all inputs as they happen; or even in normal mode failing examples will print all the values used.

Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19
  • Thank you for your answer. I am using the bundle in another rule. I did not put it up because I wanted to just show the bundle I am using in my code. Does each instance of test_servicediscovery have a bundle of its own? – Aniket Sep 27 '19 at 08:36
  • I can see the failing examples and also with debug mode, I am able to see the examples Hypothesis has been trying. But I wanted to know whether a bundle is treated as a class variable or an instance variable. That is the reason I need to print a bundle or see how does it look like during each example run. – Aniket Sep 27 '19 at 08:38
  • Yeah, it's more like an instance variable. Printing it is very unlikely to be useful though... – Zac Hatfield-Dodds Oct 16 '19 at 22:58