Coverage for tests/test_fastapi_cli.py: 100%
14 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 subprocess 1abcdef
2import sys 1abcdef
3from unittest.mock import patch 1abcdef
5import fastapi.cli 1abcdef
6import pytest 1abcdef
9def test_fastapi_cli(): 1abcdef
10 result = subprocess.run( 1mnopqr
11 [
12 sys.executable,
13 "-m",
14 "coverage",
15 "run",
16 "-m",
17 "fastapi",
18 "dev",
19 "non_existent_file.py",
20 ],
21 capture_output=True,
22 encoding="utf-8",
23 )
24 assert result.returncode == 1, result.stdout 1mnopqr
25 assert "Path does not exist non_existent_file.py" in result.stdout 1mnopqr
28def test_fastapi_cli_not_installed(): 1abcdef
29 with patch.object(fastapi.cli, "cli_main", None): 1ghijkl
30 with pytest.raises(RuntimeError) as exc_info: 1ghijkl
31 fastapi.cli.main() 1ghijkl
32 assert "To use the fastapi command, please install" in str(exc_info.value) 1ghijkl