Skip to content

Commit d280639

Browse files
committed
Fix cli tests for exit called
1 parent 5ae64ca commit d280639

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/test_cli.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# SPDX-License-Identifier: BSD-2-Clause
2+
3+
import pytest
24
import unittest
35
from unittest import mock
46
import logging
@@ -9,6 +11,7 @@
911

1012
class MockCommand:
1113
"""Mock command for testing CLI"""
14+
1215
def build_cli_parser(self, parser):
1316
parser.add_argument("--option", help="Test option")
1417
parser.add_argument("action", choices=["valid", "error", "unexpected"])
@@ -74,8 +77,12 @@ def test_run_command_error(self, mock_get_cls, mock_pin_command, mock_parse_conf
7477

7578
# Capture stdout for assertion
7679
with mock.patch("builtins.print") as mock_print:
77-
# Run with error action
78-
run(["test", "error"])
80+
with pytest.raises(SystemExit) as systemexit:
81+
# Run with error action
82+
run(["test", "error"])
83+
84+
assert systemexit.type is SystemExit
85+
assert systemexit.value.code == 1
7986

8087
# Error message should be printed
8188
mock_print.assert_called_once()
@@ -104,8 +111,12 @@ def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_c
104111

105112
# Capture stdout for assertion
106113
with mock.patch("builtins.print") as mock_print:
107-
# Run with unexpected error action
108-
run(["test", "unexpected"])
114+
with pytest.raises(SystemExit) as systemexit:
115+
# Run with unexpected error action
116+
run(["test", "unexpected"])
117+
118+
assert systemexit.type is SystemExit
119+
assert systemexit.value.code == 1
109120

110121
# Error message should be printed
111122
mock_print.assert_called_once()
@@ -206,4 +217,4 @@ def test_verbosity_flags(self, mock_get_cls, mock_pin_command, mock_parse_config
206217
self.assertEqual(logging.getLogger().level, logging.DEBUG)
207218
finally:
208219
# Restore original log level
209-
logging.getLogger().setLevel(original_level)
220+
logging.getLogger().setLevel(original_level)

0 commit comments

Comments
 (0)