asyncflux.testing – Unit testing support for asynchronous code

Unit testing support for asynchronous code

class asyncflux.testing.AsyncfluxTestCase(methodName='runTest', **kwargs)[source]

Bases: tornado.testing.AsyncTestCase

assert_mock_args(fetch_mock, path, method='GET', body=None, auth_username='root', auth_password='root', *args, **kwargs)[source]
patch_fetch_mock(client)[source]
setup_fetch_mock(fetch_mock, status_code, **kwargs)[source]
stop_op(result, error)[source]
asyncflux.testing.gen_test(func=None, timeout=None)[source]

Testing equivalent of @gen.coroutine, to be applied to test methods.

@gen.coroutine cannot be used on tests because the .IOLoop is not already running. @gen_test should be applied to test methods on subclasses of AsyncTestCase.

Example:

class MyTest(AsyncHTTPTestCase):
    @gen_test
    def test_something(self):
        response = yield gen.Task(self.fetch('/'))

By default, @gen_test times out after 5 seconds. The timeout may be overridden globally with the ASYNC_TEST_TIMEOUT environment variable, or for each test with the timeout keyword argument:

class MyTest(AsyncHTTPTestCase):
    @gen_test(timeout=10)
    def test_something_slow(self):
        response = yield gen.Task(self.fetch('/'))

New in version 3.1: The timeout argument and ASYNC_TEST_TIMEOUT environment variable.

Changed in version 4.0: The wrapper now passes along *args, **kwargs so it can be used on functions with arguments.