diff --git a/tests/base.py b/tests/base.py index 7f90e35e..0a9401f4 100644 --- a/tests/base.py +++ b/tests/base.py @@ -142,7 +142,7 @@ async def run_pagination_test( *[f"limit-offset-{key}" for key in _params_desc], ], ) - @mark.asyncio + @mark.asyncio(loop_scope="session") async def test_pagination( self, client, diff --git a/tests/ext/test_cassandra.py b/tests/ext/test_cassandra.py index a25316a9..209d2581 100644 --- a/tests/ext/test_cassandra.py +++ b/tests/ext/test_cassandra.py @@ -48,7 +48,7 @@ def route(): return add_pagination(app) -@mark.asyncio +@mark.asyncio(loop_scope="session") async def test_cursor(app, client, entities): entities = sorted(parse_obj_as(List[UserOut], entities), key=(lambda it: (it.id, it.name))) diff --git a/tests/ext/test_sqlalchemy_cursor.py b/tests/ext/test_sqlalchemy_cursor.py index fca37f84..cc417fb7 100644 --- a/tests/ext/test_sqlalchemy_cursor.py +++ b/tests/ext/test_sqlalchemy_cursor.py @@ -47,7 +47,7 @@ def route_on_order(db: Session = Depends(get_db)): @sqlalchemy20 -@mark.asyncio +@mark.asyncio(loop_scope="session") async def test_cursor(app, client, entities): entities = sorted(parse_obj_as(List[UserOut], entities), key=(lambda it: (it.id, it.name))) @@ -90,7 +90,7 @@ async def test_cursor(app, client, entities): @sqlalchemy20 -@mark.asyncio +@mark.asyncio(loop_scope="session") async def test_cursor_refetch(app, client, entities, postgres_url): entities = sorted(parse_obj_as(List[UserOut], entities), key=(lambda it: (it.id, it.name))) first_85_entities = entities[:85] @@ -180,7 +180,7 @@ async def test_cursor_refetch(app, client, entities, postgres_url): @sqlalchemy20 -@mark.asyncio +@mark.asyncio(loop_scope="session") async def test_no_order(app, client, entities): with raises( ValueError, diff --git a/tests/patch.py b/tests/patch.py index fd166037..e2259e85 100644 --- a/tests/patch.py +++ b/tests/patch.py @@ -1,5 +1,19 @@ +import asyncio +from functools import lru_cache + from pydantic import generics # https://github.com/pydantic/pydantic/issues/4483 generics._generic_types_cache = {} generics._assigned_parameters = {} + + +@lru_cache() +def _get_event_loop_no_warn(*_): + loop = asyncio.new_event_loop() + loop.__pytest_asyncio = True + + return loop + + +# plugin._get_event_loop_no_warn = _get_event_loop_no_warn