TestClient on mac takes exactly 30s for every .get call
See original GitHub issueI previously opened this issue at FastAPI: https://github.com/tiangolo/fastapi/issues/1567, but traced the problem to Starlette.
Details
On Mac with new install of Starlette, every call to TestClient.get()
takes exactly 30s to complete. The response, when it arrives, is correct.
Environment
- OS: Macbook Pro 10.13.6
- Starlette version: 0.13.4
- Python version: 3.6
Example
Copy and paste the example from the Starlette docs https://www.starlette.io/testclient/ into a brand new venv:
from starlette.responses import HTMLResponse
from starlette.testclient import TestClient
async def app(scope, receive, send):
assert scope['type'] == 'http'
response = HTMLResponse('<html><body>Hello, world!</body></html>')
await response(scope, receive, send)
def test_app():
client = TestClient(app)
response = client.get('/')
assert response.status_code == 200
Alternatively, you can clone the repo at https://github.com/charlesbaynham/fastapi_mwe and use the requirements.txt to duplicate my environment. Running python test_starlette.py
takes 30s. This repo also contains a cProfile of the test which looks like this:
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Test Client - Starlette
The test client allows you to make requests against your ASGI application, ... Set headers for each request separately response = client.get("/", ...
Read more >Make and receive phone calls on Mac or iPad - Apple Support
On your Mac, open the FaceTime app, choose FaceTime > Settings (or Preferences), then select Calls From iPhone.
Read more >Save disk space with OneDrive Files On-Demand for Mac
When you turn on Files On-Demand, you'll see all your files in Mac Finder and get ... appear as online-only files, which don't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my case, each test takes around 7.5 seconds to run, by @erewok comment, I took a look at TestClient which defines
base_url
as ‘http://testserver’ by default, which is not resolvable of course.So I changed the call to TestClient for this:
client = TestClient(app, base_url='http://localhost')
Now the test runs in 0.3s, this is running MacOS 10.14.6 in a MacBook Pro, Python 3.8.0.
Hope this helps some else.
That sounds familiar, I’ve been messing around with OpenWRT recently. Thanks for your help and sorry to have wasted your time!