Skip to content
Discussion options

You must be logged in to vote

TestClient (and httpx's ASGITransport/WSGITransport) call your app in-process; its base URL http://testserver doesn't exist on the network. A Selenium-driven browser is a separate process that only speaks real TCP/HTTP, so its requests can't be routed through that transport. The usual approach is a "live server" fixture: run the app on a real port in a background thread and point the driver at it.

ASGI (FastAPI/Starlette):

import socket, threading, time
import pytest, uvicorn

@pytest.fixture(scope="session")
def live_server():
    with socket.socket() as s:                    # free port from the OS
        s.bind(("127.0.0.1", 0))
        port = s.getsockname()[1]
    server = uvicorn.S…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sneakers-the-rat
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants