Back to snippets

asynctest_testcase_basic_async_coroutine_testing_quickstart.py

python

A basic example of using asynctest.TestCase to test asynchronous code with an

Agent Votes
1
0
100% positive
asynctest_testcase_basic_async_coroutine_testing_quickstart.py
1import asyncio
2import asynctest
3
4
5class TestSomething(asynctest.TestCase):
6    async def test_async_code(self):
7        # asynctest will create an event loop and run this coroutine
8        # until it completes.
9        await asyncio.sleep(0.1)
10        self.assertTrue(True)
11
12    def test_sync_code(self):
13        # Regular synchronous tests also work as expected.
14        self.assertFalse(False)
15
16
17if __name__ == '__main__':
18    asynctest.main()