1

I have this code:

import pytest


@pytest.fixture
async def my_fixture():
    result = 5
    yield result
    print("Db connection closing or smth yet")


@pytest.mark.asyncio
async def test_my_fixt(my_fixture):
    assert my_fixture == 5

If I run this I will have

FAILED tests/t.py::test_my_fixt - assert <async_generator object my_fixture at 0x7fa13415c450> == 5

Is there anything I can do to make my_fixture return just 5, not AsyncGenerator?

KrySeyt
  • 31
  • 2
  • 2
    You need to install the pytest asyncio plugin. See https://stackoverflow.com/a/73499640/3280538 – flakes Jan 28 '23 at 18:42
  • Does this answer your question? [Async fixtures with pytest](https://stackoverflow.com/questions/49936724/async-fixtures-with-pytest) – Fractalism Jan 28 '23 at 18:49

0 Answers0