Skip to content

fix: Tests - Update middleware tests to use Starlette 1.0.0 routing API#218

Open
morgan-wowk wants to merge 1 commit intomasterfrom
starlette-tests
Open

fix: Tests - Update middleware tests to use Starlette 1.0.0 routing API#218
morgan-wowk wants to merge 1 commit intomasterfrom
starlette-tests

Conversation

@morgan-wowk
Copy link
Copy Markdown
Collaborator

@morgan-wowk morgan-wowk commented Apr 24, 2026

Problem

The test suite was using Starlette's deprecated @app.route() decorator to register route handlers in middleware and concurrency tests. This API was removed in Starlette 1.0.0, causing 12 tests to fail with AttributeError: 'Starlette' object has no attribute 'route'.

Fix

Updated the affected tests in test_instrumentation_request_middleware.py and test_request_id_concurrency.py to use the current Starlette routing API — defining handlers as plain functions and passing them to the Starlette constructor via Route objects:

# Before
app = Starlette()
app.add_middleware(RequestContextMiddleware)

@app.route("/test")
def handler(request):
    ...

# After
def handler(request):
    ...

app = Starlette(routes=[Route("/test", handler)])
app.add_middleware(RequestContextMiddleware)

Backwards Compatibility

Starlette(routes=[Route(...)]) is the recommended API and works across all supported Starlette versions, so this change is fully backwards compatible.

References

Screenshots / links

image.png

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@morgan-wowk morgan-wowk marked this pull request as ready for review April 24, 2026 19:13
@morgan-wowk morgan-wowk requested a review from Ark-kun as a code owner April 24, 2026 19:13
@morgan-wowk morgan-wowk requested a review from yuechao-qin April 24, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant