Search code examples
pythonpython-asynciopython-3.5aiohttp

How to unittest aiohttp.web applications


Given an aiohttp.web application with views like this one:

async def hello(request):
    return web.Response(body=b"Hello, world")

I'm trying to understand how to properly unit-test them.

I normally use Django's own test client when writing Django apps, and was looking for something similar for aiohttp.web. I'm not sure this is the right approach or not.

TL;DR: How do I simulate a request to an aiohttp.web app in a unittest?


Solution

  • You may create web server and perform real HTTP requests without simulation.

    See https://github.com/KeepSafe/aiohttp/blob/master/tests/test_client_functional.py for example.