question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test from FastAPI example in the docs passes with 12 warnings

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

I followed the FastAPI example in the docs, everything works well except the test part. It passes, but with 12 warnings. Here’s the output after running the test:

(venv) C:\Users\user\bexil\transposec\transposec>pytest
================================================= test session starts =================================================
platform win32 -- Python 3.8.7, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: C:\Users\user\bexil\transposec\transposec
collected 1 item

users\users_test.py .                                                                                            [100%]

================================================== warnings summary ===================================================
..\venv\lib\site-packages\asynctest\mock.py:434
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\mock.py:434: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def wait(self, skip=0):

..\venv\lib\site-packages\asynctest\mock.py:448
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\mock.py:448: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def wait_next(self, skip=0):

..\venv\lib\site-packages\asynctest\mock.py:468
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\mock.py:468: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def wait_for(self, predicate):

..\venv\lib\site-packages\asynctest\mock.py:489
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\mock.py:489: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def _notify(self):

..\venv\lib\site-packages\asynctest\case.py:357
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:357: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def doCleanups(self):

..\venv\lib\site-packages\asynctest\case.py:381
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:381: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def assertAsyncRaises(self, exception, awaitable):

..\venv\lib\site-packages\asynctest\case.py:392
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:392: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def assertAsyncRaisesRegex(self, exception, regex, awaitable):

..\venv\lib\site-packages\asynctest\case.py:403
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:403: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def assertAsyncWarns(self, warning, awaitable):

..\venv\lib\site-packages\asynctest\case.py:414
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:414: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def assertAsyncWarnsRegex(self, warning, regex, awaitable):

..\venv\lib\site-packages\asynctest\case.py:445
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:445: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def advance(self, seconds):

..\venv\lib\site-packages\asynctest\case.py:487
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\case.py:487: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def _drain_loop(self):

..\venv\lib\site-packages\asynctest\helpers.py:13
  c:\users\user\bexil\transposec\venv\lib\site-packages\asynctest\helpers.py:13: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def exhaust_callbacks(loop):

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================================== 1 passed, 12 warnings in 1.74s ============================================

To Reproduce Steps to reproduce the behavior, preferably a small code snippet.

Follow the FastAPI example in the docs. Note that having test_create_user() assert 1 == 1 or otherwise doesn’t change the outcome.

import asyncio
from typing import Generator

import pytest
from fastapi.testclient import TestClient
from tortoise.contrib.test import finalizer, initializer

from main import app



@pytest.fixture(scope='module')
def client() -> Generator:
    initializer(['models'])
    with TestClient(app) as c:
        yield c
    finalizer()


@pytest.fixture(scope='module')
def event_loop(client: TestClient) -> Generator:
    yield client.task.get_loop()


def test_create_user(client: TestClient, event_loop: asyncio.AbstractEventLoop):
    assert 1 == 1

Expected behavior A clear and concise description of what you expected to happen.

I expected the test to pass without warnings, like this for example:

(venv) C:\Users\user\bexil\transposec\transposec>pytest
================================================= test session starts =================================================
platform win32 -- Python 3.8.7, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: C:\Users\user\bexil\transposec\transposec
collected 1 item

users\users_test.py .                                                                                            [100%]

================================================== 1 passed in 1.74s ==================================================

Additional context Add any other context about the problem here.

I also had to install asynctest in the process.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bunya017commented, Feb 19, 2021

ran into the same problem, it appears that asynctest is no longer being maintained: see Martiusweb/asynctest#158

Thanks for the reply, I’m now using SQLAlchemy instead 😅.\

Coming from Django, using Tortoise-ORM was great because of its likeness with Django-ORM. The major problem I faced was getting nested relationships to work properly with tortoise-orm and Pydantic. I settled for SQLAlchemy because everything just works, no tweaks! The syntax was weird at the beginnig tho.

0reactions
long2icecommented, Nov 15, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing - FastAPI
Create a TestClient by passing your FastAPI application to it. ... Now let's extend this example and add more details to see how...
Read more >
Build and Secure an API in Python with FastAPI
To test the authorization flow, click the grey lock in the top right corner of the endpoint. Enter your Okta client ID and...
Read more >
latest PDF - pytest Documentation
The first test passed and the second failed. ... Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ... pytest-fastapi.
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
As an example, the following could be passed for faster compression and to ... If error_bad_lines is False , and warn_bad_lines is True...
Read more >
How to add both file and JSON body in a FastAPI POST ...
As per FastAPI documentation: You can declare multiple Form parameters in a path operation, but you can't also declare Body fields that you ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found