Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 9a794e3

Browse files
author
Luke Hinds
authored
Merge pull request #72 from stacklok/fix-ci
mock uvicorn.run in CLI serve command tests
2 parents 4d47146 + 72ace45 commit 9a794e3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/test_cli.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def test_cli_version(cli_runner: CliRunner) -> None:
3232

3333
def test_serve_default_options(cli_runner: CliRunner, mock_logging: Any) -> None:
3434
"""Test serve command with default options."""
35-
with patch("logging.getLogger") as mock_logger:
35+
with patch("logging.getLogger") as mock_logger, \
36+
patch("uvicorn.run") as mock_run:
3637
logger_instance = mock_logger.return_value
3738
result = cli_runner.invoke(cli, ["serve"])
3839

@@ -47,11 +48,13 @@ def test_serve_default_options(cli_runner: CliRunner, mock_logging: Any) -> None
4748
"log_format": "JSON",
4849
},
4950
)
51+
mock_run.assert_called_once()
5052

5153

5254
def test_serve_custom_options(cli_runner: CliRunner, mock_logging: Any) -> None:
5355
"""Test serve command with custom options."""
54-
with patch("logging.getLogger") as mock_logger:
56+
with patch("logging.getLogger") as mock_logger, \
57+
patch("uvicorn.run") as mock_run:
5558
logger_instance = mock_logger.return_value
5659
result = cli_runner.invoke(
5760
cli,
@@ -79,6 +82,7 @@ def test_serve_custom_options(cli_runner: CliRunner, mock_logging: Any) -> None:
7982
"log_format": "TEXT",
8083
},
8184
)
85+
mock_run.assert_called_once()
8286

8387

8488
def test_serve_invalid_port(cli_runner: CliRunner) -> None:
@@ -103,7 +107,8 @@ def test_serve_with_config_file(
103107
cli_runner: CliRunner, mock_logging: Any, temp_config_file: Path
104108
) -> None:
105109
"""Test serve command with config file."""
106-
with patch("logging.getLogger") as mock_logger:
110+
with patch("logging.getLogger") as mock_logger, \
111+
patch("uvicorn.run") as mock_run:
107112
logger_instance = mock_logger.return_value
108113
result = cli_runner.invoke(cli, ["serve", "--config", str(temp_config_file)])
109114

@@ -118,6 +123,7 @@ def test_serve_with_config_file(
118123
"log_format": "JSON",
119124
},
120125
)
126+
mock_run.assert_called_once()
121127

122128

123129
def test_serve_with_nonexistent_config_file(cli_runner: CliRunner) -> None:
@@ -131,7 +137,8 @@ def test_serve_priority_resolution(
131137
cli_runner: CliRunner, mock_logging: Any, temp_config_file: Path, env_vars: Any
132138
) -> None:
133139
"""Test serve command respects configuration priority."""
134-
with patch("logging.getLogger") as mock_logger:
140+
with patch("logging.getLogger") as mock_logger, \
141+
patch("uvicorn.run") as mock_run:
135142
logger_instance = mock_logger.return_value
136143
result = cli_runner.invoke(
137144
cli,
@@ -161,6 +168,7 @@ def test_serve_priority_resolution(
161168
"log_format": "TEXT",
162169
},
163170
)
171+
mock_run.assert_called_once()
164172

165173

166174
def test_main_function() -> None:

0 commit comments

Comments
 (0)