How to parametrize asynchronous tests
The pytest.mark.parametrize marker works with asynchronous tests the same as with synchronous tests. You can apply both pytest.mark.asyncio and pytest.mark.parametrize to asynchronous test functions:
import asyncio
import pytest
@pytest.mark.asyncio
@pytest.mark.parametrize("value", [1, 2, 3])
async def test_parametrized_async_function(value):
await asyncio.sleep(1)
assert value > 0
Note
Whilst asynchronous tests can be parametrized, each individual test case still runs sequentially, not concurrently. For more information about how pytest-asyncio executes tests, see Test execution and concurrency.