Coverage for tests/test_fastapi_cli.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1import subprocess 1abcde
2import sys 1abcde
3from unittest.mock import patch 1abcde
5import fastapi.cli 1abcde
6import pytest 1abcde
9def test_fastapi_cli(): 1abcde
10 result = subprocess.run( 1abcde
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 1abcde
25 assert "Using path non_existent_file.py" in result.stdout 1abcde
28def test_fastapi_cli_not_installed(): 1abcde
29 with patch.object(fastapi.cli, "cli_main", None): 1abcde
30 with pytest.raises(RuntimeError) as exc_info: 1abcde
31 fastapi.cli.main() 1abcde
32 assert "To use the fastapi command, please install" in str(exc_info.value) 1abcde