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