spawn_uvicorn#
- safir.testing.uvicorn.spawn_uvicorn(*, working_directory, app=None, factory=None, capture=False, timeout=5.0, env=None)#
Spawn an ASGI app as a separate Uvicorn process.
The current working directory will always be added to the Python path, so
app
andfactory
can point to modules found relative to the current working directory, or relative to theworking_directory
parameter.- Parameters:
working_directory (
str
|Path
) – Directory in which Uvicorn should run. Normally this should come from thetmp_path
fixture.app (
Optional
[str
], default:None
) – Module and variable name of the app. Either this orfactory
must be given.factory (
Optional
[str
], default:None
) – Module name and callable that will create the app object. Either this orapp
must be given.capture (
bool
, default:False
) – Whether to capture standard output and standard error of Uvicorn. If set to true, both will be automatically decoded as UTF-8 text and will be available in theprocess
attribute of the returned object.timeout (
float
, default:5.0
) – How long to wait in seconds.env (
Optional
[dict
[str
,str
]], default:None
) – Extra environment variable settings.
- Returns:
Properties of the running Uvicorn service.
- Return type:
- Raises:
ServerNotListeningError – Server did not start within the timeout. Generally this means it had some fatal error during startup.
ValueError – Either both or neither of app and factory were given.