Coverage for tests/test_fastapi_cli.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1import subprocess 1abcde

2import sys 1abcde

3from unittest.mock import patch 1abcde

4 

5import fastapi.cli 1abcde

6import pytest 1abcde

7 

8 

9def test_fastapi_cli(): 1abcde

10 result = subprocess.run( 1klmno

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 1klmno

25 assert "Path does not exist non_existent_file.py" in result.stdout 1klmno

26 

27 

28def test_fastapi_cli_not_installed(): 1abcde

29 with patch.object(fastapi.cli, "cli_main", None): 1fghij

30 with pytest.raises(RuntimeError) as exc_info: 1fghij

31 fastapi.cli.main() 1fghij

32 assert "To use the fastapi command, please install" in str(exc_info.value) 1fghij