Coverage for tests/test_tutorial/test_background_tasks/test_tutorial002.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1import importlib 1abcdef
2import os 1abcdef
3from pathlib import Path 1abcdef
5import pytest 1abcdef
6from fastapi.testclient import TestClient 1abcdef
8from ...utils import needs_py39, needs_py310 1abcdef
11@pytest.fixture( 1abcdef
12 name="client",
13 params=[
14 "tutorial002",
15 pytest.param("tutorial002_py310", marks=needs_py310),
16 "tutorial002_an",
17 pytest.param("tutorial002_an_py39", marks=needs_py39),
18 pytest.param("tutorial002_an_py310", marks=needs_py310),
19 ],
20)
21def get_client(request: pytest.FixtureRequest): 1abcdef
22 mod = importlib.import_module(f"docs_src.background_tasks.{request.param}") 1abcdef
24 client = TestClient(mod.app) 1abcdef
25 return client 1abcdef
28def test(client: TestClient): 1abcdef
29 log = Path("log.txt") 1ghijkl
30 if log.is_file(): 1ghijkl
31 os.remove(log) # pragma: no cover 1ghijkl
32 response = client.post("/send-notification/foo@example.com?q=some-query") 1ghijkl
33 assert response.status_code == 200, response.text 1ghijkl
34 assert response.json() == {"message": "Message sent"} 1ghijkl
35 with open("./log.txt") as f: 1ghijkl
36 assert "found query: some-query\nmessage to foo@example.com" in f.read() 1ghijkl