diff --git a/poetry.lock b/poetry.lock index afb15098..8590509b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1690,21 +1690,21 @@ dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments [[package]] name = "pytest-asyncio" -version = "0.21.2" +version = "0.24.0" description = "Pytest support for asyncio" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest_asyncio-0.21.2-py3-none-any.whl", hash = "sha256:ab664c88bb7998f711d8039cacd4884da6430886ae8bbd4eded552ed2004f16b"}, - {file = "pytest_asyncio-0.21.2.tar.gz", hash = "sha256:d67738fc232b94b326b9d060750beb16e0074210b98dd8b58a5239fa2a154f45"}, + {file = "pytest_asyncio-0.24.0-py3-none-any.whl", hash = "sha256:a811296ed596b69bf0b6f3dc40f83bcaf341b155a269052d82efa2b25ac7037b"}, + {file = "pytest_asyncio-0.24.0.tar.gz", hash = "sha256:d081d828e576d85f875399194281e92bf8a68d60d72d1a2faf2feddb6c46b276"}, ] [package.dependencies] -pytest = ">=7.0.0" +pytest = ">=8.2,<9" [package.extras] docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] -testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] [[package]] name = "pytest-cov" @@ -2431,4 +2431,4 @@ tortoise = ["tortoise-orm"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "8e89a681b50d64fa8ba1e5e39773db17f1884c28359b848e6df42ceca58c704e" +content-hash = "bf3fd0d81c0e3f0bd8a9330ec44daa612ad667a1e8d64c6d8990870d4d65b611" diff --git a/pyproject.toml b/pyproject.toml index 4d4dd757..8329603e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ bunnet = {version = "^1.1.0", optional = true} fastapi = ">=0.93.0" pytest = "^8.3.2" pytest-cov = "^5.0.0" -pytest-asyncio = "^0.21.1" +pytest-asyncio = "^0.24.0" flaky = "^3.8.1" pre-commit = "^3.5.0" Faker = "^28.4.1" diff --git a/pytest.ini b/pytest.ini index 67aee92e..606ce8fa 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,5 @@ [pytest] +asyncio_default_fixture_loop_scope=session addopts = --cov=fastapi_pagination 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