mirror of https://github.com/tiangolo/fastapi.git
25 lines
635 B
Python
25 lines
635 B
Python
from fastapi import BackgroundTasks, FastAPI
|
|
from fastapi.testclient import TestClient
|
|
from starlette.responses import BackgroundTask, Response
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/")
|
|
def endpoint(tasks: BackgroundTasks):
|
|
tasks.add_task(lambda: print("Dependency task executed"))
|
|
return Response(
|
|
content="Custom response",
|
|
background=BackgroundTask(lambda: print("Response task executed")),
|
|
)
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_issue_11215(capsys):
|
|
client.get("/")
|
|
captured = capsys.readouterr()
|
|
assert "Dependency task executed" in captured.out
|
|
assert "Response task executed" in captured.out
|