fix fastapi tests failure with >= 0.118.0 (#4277)

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This commit is contained in:
Emídio Neto
2026-03-06 07:48:51 -03:00
committed by GitHub
parent 88e5bfc630
commit d7a3b18760
2 changed files with 11 additions and 5 deletions

View File

@@ -1,18 +1,18 @@
annotated-types==0.7.0
anyio==4.3.0
anyio==4.12.1
asgiref==3.8.1
certifi==2024.7.4
charset-normalizer==3.3.2
Deprecated==1.2.14
exceptiongroup==1.2.0
fastapi==0.117.0
fastapi==0.126.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
idna==3.7
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
pluggy==1.6.0
py-cpuinfo==9.0.0
pydantic==2.12.5
pydantic_core==2.41.5

View File

@@ -25,6 +25,7 @@ from unittest.mock import Mock, call, patch
import fastapi
import pytest
from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
from fastapi.responses import JSONResponse, PlainTextResponse
from fastapi.routing import APIRoute
@@ -2073,7 +2074,12 @@ class TestFastAPIFallback(TestBaseFastAPI):
app = TestBaseFastAPI._create_fastapi_app()
def build_middleware_stack():
return app.router
# Return something that is NOT a ServerErrorMiddleware so the
# instrumentation fallback path triggers, but still wrap the
# router with AsyncExitStackMiddleware so that newer FastAPI
# versions (which assert ``fastapi_middleware_astack`` exists in
# the request scope) can service requests normally.
return AsyncExitStackMiddleware(app.router)
app.build_middleware_stack = build_middleware_stack
return app
@@ -2098,7 +2104,7 @@ class TestFastAPIFallback(TestBaseFastAPI):
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0].getMessage(),
"Skipping FastAPI instrumentation due to unexpected middleware stack: expected ServerErrorMiddleware, got <class 'fastapi.routing.APIRouter'>",
"Skipping FastAPI instrumentation due to unexpected middleware stack: expected ServerErrorMiddleware, got <class 'fastapi.middleware.asyncexitstack.AsyncExitStackMiddleware'>",
)