tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.69k stars 390 forks source link

Fixes pytest-asyncio warning for `event_loop` fixture #1760

Closed waketzheng closed 2 weeks ago

waketzheng commented 2 weeks ago

Unittest of blacksheep example print the following warnings:

/Users/mac10.12/Library/Caches/pypoetry/virtualenvs/tortoise-orm-iT379CwK-py3.11/lib/python3.11/site-packages/pytest_asyncio/plugin.py:208: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
====================================================== test session starts =======================================================
platform darwin -- Python 3.11.9, pytest-8.3.3, pluggy-1.5.0
rootdir: /Users/mac10.12/github/tortoise-orm
configfile: pyproject.toml
plugins: asyncio-0.24.0, cov-5.0.0, anyio-4.5.2, xdist-3.6.1
asyncio: mode=Mode.STRICT, default_loop_scope=None
collected 4 items

examples/blacksheep/_tests.py ....                                                                                         [100%]

======================================================== warnings summary ========================================================
examples/blacksheep/_tests.py::test_get_uses_list
  /Users/mac10.12/Library/Caches/pypoetry/virtualenvs/tortoise-orm-iT379CwK-py3.11/lib/python3.11/site-packages/pytest_asyncio/plugin.py:783: DeprecationWarning: The event_loop fixture provided by pytest-asyncio has been redefined in
  /Users/mac10.12/github/tortoise-orm/examples/blacksheep/_tests.py:18
  Replacing the event_loop fixture with a custom implementation is deprecated
  and will lead to errors in the future.
  If you want to request an asyncio event loop with a scope other than function
  scope, use the "scope" argument to the asyncio mark when marking the tests.
  If you want to return different types of event loops, use the event_loop_policy
  fixture.

    warnings.warn(

examples/blacksheep/_tests.py::test_get_uses_list
examples/blacksheep/_tests.py::test_create_user
examples/blacksheep/_tests.py::test_update_user
  /Users/mac10.12/Library/Caches/pypoetry/virtualenvs/tortoise-orm-iT379CwK-py3.11/lib/python3.11/site-packages/pydantic/main.py:1114: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', category=PydanticDeprecatedSince20)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

How to reproduce:

TORTOISE_TEST_DB=sqlite://:memory: PYTHONPATH=examples/blacksheep pytest examples/blacksheep/_tests.py

Since pytest-asyncio>=0.24, the loop_scope argument was supported, so I upgrade the package and apply this argument.

coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 11721656067

Details


Totals Coverage Status
Change from base Build 11660093686: 0.0%
Covered Lines: 6025
Relevant Lines: 6650

💛 - Coveralls