Pre-existing test_startup_logs_warning_when_running_as_root fails under ASGITransport
#655
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
Reproduces on
mainas well — predates PR #653 and #652.Root cause
The test uses
AsyncClient(transport=ASGITransport(app=app), ...)andexpects the FastAPI
lifespanto fire, which would emit theRunning as root — CIS Docker §4.1 violationwarning.httpx'sASGITransportdoes not run the lifespan by default — it only proxiesHTTP scope requests. So the lifespan startup code never executes, caplog
captures nothing, and the assertion fails.
The metrics suite already hit the same wall and routes around it with:
(see
test_ocr_models_ready_gauge_is_one_after_lifespan_startup).Proposed fix
Migrate
test_startup_logs_warning_when_running_as_rootand its siblingtest_startup_does_not_warn_when_running_as_non_rootto drive thelifespan directly via
app.router.lifespan_context(app)(same pattern astest_metrics.py). The runtime mock ofos.getuid()stays as-is.Alternative: use
httpx.ASGITransport(app=app, lifespan="on"), but onlyrecent httpx versions accept that argument — check the pinned version
before relying on it.
Acceptance criteria
test_startup_logs_warning_when_running_as_rootpasses.test_startup_does_not_warn_when_running_as_non_rootstill passes.ASGITransportexamples (only if a future grep would benefit).Related
ocr-service/test_metrics.py::test_ocr_models_ready_gauge_is_one_after_lifespan_startup