Coverage for tests / test_tutorial / test_background_tasks / test_tutorial001.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import os 1defg

2from pathlib import Path 1defg

3 

4from fastapi.testclient import TestClient 1defg

5 

6from docs_src.background_tasks.tutorial001_py310 import app 1defg

7 

8client = TestClient(app) 1defg

9 

10 

11def test(): 1defg

12 log = Path("log.txt") 1abc

13 if log.is_file(): 1abc

14 os.remove(log) # pragma: no cover 

15 response = client.post("/send-notification/foo@example.com") 1abc

16 assert response.status_code == 200, response.text 1abc

17 assert response.json() == {"message": "Notification sent in the background"} 1abc

18 with open("./log.txt") as f: 1abc

19 assert "notification for foo@example.com: some notification" in f.read() 1abc