AttributeError error in pytest when trying to make an orm request

46 Views Asked by At

I want to check the data that I receive from the FastAPI handle, when I try to make an orm request I get an error. I'm using Pytest-asyncio

I checked the session, the database is fine with them

@pytest.fixture
async def db():
    async with async_session_maker() as session:
        yield session


app.dependency_overrides[db] = db


@pytest.fixture(autouse=True, scope='session')
async def prepare_db():
    async with test_engine.begin() as conn:
        await conn.run_sync(metadata.create_all)
    yield
    async with test_engine.begin() as conn:
        await conn.run_sync(metadata.drop_all)


@pytest.fixture(scope='session')
def event_loop(request):
    loop = asyncio.get_event_loop_policy().new_event_loop()
    yield loop
    loop.close()


client = TestClient(app)


@pytest.fixture(scope='session')
async def ac():
    async with AsyncClient(app=app, base_url="http://test") as ac:
        yield ac

#test file
@pytest.mark.asyncio
async def test_get_menu(ac: AsyncClient, db):
    menu_id = id_dict['menu_id']
    menu = await db.get(Menu, menu_id)
0

There are 0 best solutions below