Creating test cases for asynchronous components
Flask 3.x supports asynchronous transactions with the asyncio platform. Chapter 5 introduced creating asynchronous API endpoint functions, web views, background tasks and services, and repository transactions using the async/await features. The test Client class of Flask 3.x is part of the Flask[async] core libraries, so there will be no problem running the async components with pytest.
The following test cases on the asynchronous repository layer, Celery tasks, and API endpoints will provide proof on pytest supporting Flask 3.x asynchronous platform.
Testing asynchronous views and API endpoint function
The test Client can run and test this async route function similar to running standard Flask routes using its get(), post(), delete(), patch(), and put() methods. In other words, the same testing rules apply to testing asynchronous view functions, as shown in the following test case:
import pytest from main import app as flask_app...