Classes
TestServer
11
▼
TestServer
11
▼
Methods
host
0
str
▼
The host the server is bound to.
property
host
0
str
▼
def host(self) -> str
Returns
str
port
0
int
▼
The actual port the server is listening on (useful with ``port=0``).
property
port
0
int
▼
def port(self) -> int
Returns
int
url
0
str
▼
Base URL for the running server (e.g. ``http://127.0.0.1:54321``).
property
url
0
str
▼
def url(self) -> str
Returns
str
is_running
0
bool
▼
Whether the server background thread is alive.
property
is_running
0
bool
▼
def is_running(self) -> bool
Returns
bool
start
1
▼
Start the server in a background thread. Blocks until ready.
start
1
▼
def start(self, *, timeout: float = 5.0) -> None
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
— |
Default:5.0
|
stop
1
▼
Gracefully stop the server and join the background thread.
stop
1
▼
def stop(self, *, timeout: float = 5.0) -> None
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
— |
Default:5.0
|
Internal Methods 5 ▼
__init__
4
▼
__init__
4
▼
def __init__(self, app: ASGIApp, *, host: str = '127.0.0.1', port: int = 0, **config_kwargs: Any) -> None
Parameters
| Name | Type | Description |
|---|---|---|
app |
— |
|
host |
— |
Default:'127.0.0.1'
|
port |
— |
Default:0
|
**config_kwargs |
— |
__enter__
0
TestServer
▼
__enter__
0
TestServer
▼
def __enter__(self) -> TestServer
Returns
TestServer
__exit__
1
▼
__exit__
1
▼
def __exit__(self, *exc: object) -> None
Parameters
| Name | Type | Description |
|---|---|---|
*exc |
— |
__aenter__
0
TestServer
▼
async
__aenter__
0
TestServer
▼
async def __aenter__(self) -> TestServer
Returns
TestServer
__aexit__
1
▼
async
__aexit__
1
▼
async def __aexit__(self, *exc: object) -> None
Parameters
| Name | Type | Description |
|---|---|---|
*exc |
— |
Functions
serve
2
AsyncIterator[TestServer]
▼
Async context manager that starts and stops a `TestServer`.
Example::
asy…
async
serve
2
AsyncIterator[TestServer]
▼
async def serve(app: ASGIApp, **kwargs: Any) -> AsyncIterator[TestServer]
Async context manager that starts and stops aTestServer.
Example::
async with serve(app) as server:
async with httpx.AsyncClient() as client:
resp = await client.get(server.url)
Parameters
| Name | Type | Description |
|---|---|---|
app |
ASGIApp |
|
**kwargs |
Any |
Returns
AsyncIterator[TestServer]