# Is Nameko service code incompatible with the Hypothesis testing library?

**URL:** <https://discourse.nameko.io/t/is-nameko-service-code-incompatible-with-the-hypothesis-testing-library/258>\
**Category:** googlegroup\
**Created:** [June 8, 2018, 10:25am UTC](https://discourse.nameko.io/t/is-nameko-service-code-incompatible-with-the-hypothesis-testing-library/258 "2018-06-08T10:25:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Viner](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/tom_viner/32/27_2.png) [@Tom\_Viner](https://discourse.nameko.io/u/Tom_Viner)\
**Post date:** [June 8, 2018, 10:25am UTC](https://discourse.nameko.io/t/is-nameko-service-code-incompatible-with-the-hypothesis-testing-library/258/1 "2018-06-08T10:25:56Z")

</div>

Hi,

Hypothesis is a property based testing library. I tried to test Nameko  
service code with it, but had problems due to the fact it edits global  
state (random.seed(0)), while nameko does setup with eventlet.

I've asked this question on hypothesis-users  
\<[https://groups.google.com/forum/#!forum/hypothesis-users](https://groups.google.com/forum/#!forum/hypothesis-users)\>:

[https://groups.google.com/forum/#!topic/hypothesis-users/j2z7nlSz-wo](https://groups.google.com/forum/#!topic/hypothesis-users/j2z7nlSz-wo)

If anyone has used Hypothesis to test Nameko service code, I'd love to hear  
how you got on.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [June 8, 2018, 11:52am UTC](https://discourse.nameko.io/t/is-nameko-service-code-incompatible-with-the-hypothesis-testing-library/258/2 "2018-06-08T11:52:01Z")

</div>

I've not used Hypothesis, but looking at your question on hypothesis-users,  
I think there are a few things you can try:

1. Does your service under test actually use RabbitMQ? If not, removing the  
`rabbit_config` will stop Nameko trying to set up the vhosts.

2. From your comment at the end, I guess you're most interested in testing  
the paths through the service method, rather then the  
entrypoints/dependency providers? If so, you might find the  
`worker_factory` a useful helper. It gives you a service instance, so you  
can invoke service methods on it as regular methods on an object. If you  
did this you wouldn't need RabbitMQ to be running even if your service has  
AMQP extensions.

3. From what I understand, the problem is that Hypothesis is setting the  
random number generation at the process level, while another thread is in  
the process of using it . This is surely a general problem for any program  
that uses threads (green or otherwise), but there are probably a couple  
ways you can work around it:

a) Update the vhost\_pipeline  
\<[https://github.com/nameko/nameko/blob/master/nameko/testing/pytest.py#L140&gt](https://github.com/nameko/nameko/blob/master/nameko/testing/pytest.py#L140&gt); (by  
overriding or patching) to use something other than random.choice to  
generate the random names.  
b) Make sure Hypothesis sets random.seed(0) \*before\* the vhost pipeline  
thread starts running.

Hope that helps,

Matt.

> **···**
>
> On Friday, June 8, 2018 at 11:25:56 AM UTC+1, tom....@sohonet.com wrote:
> 
> > Hi,
> > 
> > Hypothesis is a property based testing library. I tried to test Nameko  
> > service code with it, but had problems due to the fact it edits global  
> > state (random.seed(0)), while nameko does setup with eventlet.
> > 
> > I've asked this question on hypothesis-users  
> > \<[Redirecting to Google Groups](https://groups.google.com/forum/#!forum/hypothesis-users&gt;:)
> > 
> > [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/hypothesis-users/j2z7nlSz-wo)
> > 
> > If anyone has used Hypothesis to test Nameko service code, I'd love to  
> > hear how you got on.
> > 
> > Thanks,  
> > Tom
