igortg/pytest-async-sqlalchemy

How to implement

Opened this issue · 0 comments

HI, i am new to the async testing with database.
Are there any examples of tests that i can generate with this library?

I followed instructions and added all required functions to the conftest.py
But then when i try to use db_session object to insert into the database i get an error

'async_generator' object has no attribute 'execute'

The code in the test:

@pytest_asyncio.fixture()
async def sample_data(db_session: AsyncSession):
    # Create a sample data
    await db_session.execute(
        tbl_common.insert().values(
            data1="abc",
        ),
    )
    await db_session.commit()


@pytest.mark.asyncio()
async def test_get_first_liquidity_add_v3(sample_data):

    result = await get_data_from_tbl_common()
    assert result is not None
    assert result["data1"] == tbl

Did i missinterpret the usage of db_session?
I have querry functions defined in other files.
Any help would be appreciated :)