Coverage for tests/test_tutorial/test_background_tasks/test_tutorial001.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1import os 1hijklmn
2from pathlib import Path 1hijklmn
4from fastapi.testclient import TestClient 1hijklmn
6from docs_src.background_tasks.tutorial001 import app 1hijklmn
8client = TestClient(app) 1hijklmn
11def test(): 1hijklmn
12 log = Path("log.txt") 1abcdefg
13 if log.is_file(): 1abcdefg
14 os.remove(log) # pragma: no cover
15 response = client.post("/send-notification/foo@example.com") 1abcdefg
16 assert response.status_code == 200, response.text 1abcdefg
17 assert response.json() == {"message": "Notification sent in the background"} 1abcdefg
18 with open("./log.txt") as f: 1abcdefg
19 assert "notification for foo@example.com: some notification" in f.read() 1abcdefg