fix(testing): route-introspection tests for FastAPI 0.137 lazy include_router - #212
Merged
Conversation
…e_router FastAPI 0.137 / Starlette 1.3 made `include_router()` lazy: included routes no longer appear in `app.routes` (they sit behind `_IncludedRouter` wrappers and resolve only at request time). Tests that introspected `app.routes` by `.path` stopped seeing module/health routes — so `test_expected_routes_registered` and `test_registers_module_routes_with_prefix` failed even though the routes still work at runtime. (Surfaced via dependency drift since the last green run.) - Add `simple_module_test.effective_route_paths(app)`: reads the OpenAPI schema (fully-resolved prefixes) unioned with top-level mounts — version-agnostic, and the supported way to assert on registered routes. - Use it in the affected hosting/testing route tests; the absence assertions (`test_isolates_*`, `test_modules_enabled_*`) become meaningful again instead of passing vacuously under lazy inclusion. The dashboard's bare-prefix Inertia alias is `include_in_schema=False`; its behaviour stays covered by `TestProtectedPages`.
Deploying simple-module-python with
|
| Latest commit: |
ccea332
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fdb7e95b.simple-module-python.pages.dev |
| Branch Preview URL: | https://fix-fastapi-0137-route-tests.simple-module-python.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The full Python suite currently has 2 failing tests on
main:framework/hosting/tests/test_app.py::TestRouteRegistration::test_expected_routes_registeredframework/testing/tests/test_app_factory.py::TestBuildTestApp::test_registers_module_routes_with_prefixRoot cause
FastAPI 0.137 / Starlette 1.3 made
include_router()lazy. Included routes are no longer eagerly flattened intoapp.routes; eachinclude_router()now leaves a private_IncludedRouterwrapper that carries no.pathand resolves its routes only at request time. Any code that enumeratesapp.routesby.paththerefore no longer sees module API/view routes or the health router.The routes still work at runtime — every request-based test (1300+) passes, and the app serves all routes — so this is purely a static-introspection break in the test helpers. It surfaced now via dependency drift (the suite was green on these tests at the last release; a FastAPI/Starlette bump since then flipped the behaviour).
Fix
simple_module_test.effective_route_paths(app)— enumerates routes via the OpenAPI schema (a stable public API that lists every schema route with its fully-resolved prefix), unioned with any top-level mounts (StaticFiles). Version-agnostic across the eager→lazy change.test_isolates_from_other_installed_modules,test_modules_enabled_limits_loaded_modules) become meaningful again — under lazy inclusion they had started passing vacuously (the routes they checked for were hidden in the wrappers)./dashboard, registeredinclude_in_schema=False) isn't enumerable via OpenAPI; its behaviour stays covered byTestProtectedPages::test_dashboard_redirects_unauthenticated.Verification
ruff check+ruff format --check+tyon the touched packages — clean.This is the pre-existing red that also makes other PRs' CI fail (e.g. #211); merging it first turns the suite green for everyone.