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