Python 3.7
Fastapi the latest
Ubuntu 18.04
I had searching an answer in google and in manual of FastAPI, but there is no result
Example, file structure:
app
| main.py
| tests
| test_simple.py
main.py
app = FastAPI()
app.include_router(...)
app.add_middleware(...)
test_simple.py (full)
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
exception:
ImportError while importing test module '.../app/tests/test_simple.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
app/tests/test_simple.py:17: in <module>
from fastapi.testclient import TestClient
venv/lib/python3.7/site-packages/fastapi/__init__.py:7: in <module>
from .applications import FastAPI
venv/lib/python3.7/site-packages/fastapi/applications.py:3: in <module>
from fastapi import routing
venv/lib/python3.7/site-packages/fastapi/routing.py:7: in <module>
from fastapi.dependencies.utils import (
venv/lib/python3.7/site-packages/fastapi/dependencies/utils.py:20: in <module>
from fastapi.concurrency import (
venv/lib/python3.7/site-packages/fastapi/concurrency.py:5: in <module>
from starlette.concurrency import run_until_first_complete # noqa
E ImportError: cannot import name 'run_until_first_complete' from 'starlette.concurrency' (.../venv/lib/python3.7/site-packages/starlette/concurrency.py)
I think that problem is not a 'valid Python names'. It seems that in manual https://fastapi.tiangolo.com/tutorial/testing/ files main.py and test.py on the same level. But it isn't product solushion, is it?
Hi @Sanchoyzer how did you fix this?
@NMisko upgrading starlette to 0.13.2 might be required.
Yes, that was it. Thank you.
Thanks for the discussion here everyone! And thanks @Sanchoyzer for closing the issue. :+1:
Most helpful comment
@NMisko upgrading starlette to
0.13.2might be required.