I'm writing py.test tests of my code that uses the Toado library. How can I use Hypothesis in my tests that involve coroutines and the IOLoop? I've been able to write yield-based tests without Hypothesis by using pytest-toado's @pytest.mark.gen_test, but when I try to combine it with @given, I receive the following error:
FailedHealthCheck: Tests run under
@givenshould retuNone, buttest_bothretued<generator object test_both at 0x7fc4464525f0>instead.See http://hypothesis.readthedocs.org/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add
HealthCheck.retu_valueto thesuppress_health_checksettings for this test.
I'm pretty confident that this is a real problem and not just a question of disabling the health check, considering that the Hypothesis docs say
yield based tests simply won’t work.
Here's code that demonstrates my situation:
class MyHandler(RequestHandler):
@gen.coroutine
def get(self, x):
yield gen.moment
self.write(str(int(x) + 1))
self.finish()
@pytest.fixture
def app():
retu Application([(r'/([0-9]+)', MyHandler)])
@given(x=strategies.integers(min_value=0))
def test_hypothesis(x):
assert int(str(x)) == x
@pytest.mark.gen_test
def test_toado(app, http_client, base_url):
x = 123
response = yield http_client.fetch('%s/%i' % (base_url, x))
assert int(response.body) == x + 1
@pytest.mark.gen_test
@given(x=strategies.integers(min_value=0))
def test_both(x, app, http_client, base_url):
response = yield http_client.fetch('%s/%i' % (base_url, x))
assert int(response.body) == x + 1
test_hypothesis and test_toado work fine, but I get the error with test_both because I'm using yield and Hypothesis together.
Can I write tests of my Toado-based code that use Hypothesis? How?
