'For what 'pytest.mark.asyncio' is used?

I don't understand for which purposes the decorator @pytest.mark.asyncio can be used.

I've tried to run the following code snippet with pytest and pytest-asyncio plugin installed and it failed, so I concluded that pytest collects test coroutines without the decorator. Why it exists so?

async def test_div():
    return 1 / 0


Solution 1:[1]

S?awomir Lenart's answer is still correct, but note that as of pytest-asyncio>=0.17 if you add asyncio_mode = auto to your pyproject.toml or pytest.ini there is no need for the marker, i.e. this behaviour is enabled for async tests automatically.

See https://github.com/pytest-dev/pytest-asyncio#modes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 followben