A coroutine or async generator with this marker will be treated as a test function by pytest. The marked function will be executed as an asyncio task in the event loop provided by the event_loop fixture.

In order to make your test code a little more concise, the pytest pytestmark feature can be used to mark entire modules or classes with this marker. Only test coroutines will be affected (by default, coroutines prefixed by test_), so, for example, fixtures are safe to define.

import asyncio

import pytest

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio

async def test_example(event_loop):
    """No marker!"""
    await asyncio.sleep(0, loop=event_loop)

In auto mode, the pytest.mark.asyncio marker can be omitted, the marker is added automatically to async test functions.