Skip to content

Commit 0fe8c12

Browse files
committed
Add failing test for OpenAPI lifespan safety
1 parent 5f61cb4 commit 0fe8c12

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

backend/app/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
from fastapi import FastAPI
3+
from main import generate_openapi_json
4+
5+
6+
def test_openapi_failure_does_not_crash_app(monkeypatch):
7+
def broken_openapi(*args, **kwargs):
8+
raise Exception("Simulated failure")
9+
10+
monkeypatch.setattr(
11+
"main.get_openapi",
12+
broken_openapi
13+
)
14+
15+
app = FastAPI()
16+
17+
try:
18+
generate_openapi_json()
19+
started = True
20+
except Exception:
21+
started = False
22+
23+
assert started, "App should not crash if OpenAPI generation fails"
24+

0 commit comments

Comments
 (0)