async def test_aggregate_with_session(preset_documents, session): q = Sample.find(Sample.increment >= 4).aggregate( [{ "$group": { "_id": "$string", "total": { "$sum": "$integer" } } }], session=session, ) assert q.session == session q = Sample.find(Sample.increment >= 4, session=session).aggregate([{ "$group": { "_id": "$string", "total": { "$sum": "$integer" } } }]) assert q.session == session result = await q.to_list() assert len(result) == 3 assert {"_id": "test_1", "total": 2} in result assert {"_id": "test_2", "total": 6} in result assert {"_id": "test_3", "total": 3} in result