Skip to content

Commit 1be73c0

Browse files
committed
Propagate CLI subprocess exit code
1 parent 79c3a4e commit 1be73c0

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

openapi_generator_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def cli() -> None:
6161
args = []
6262
if len(sys.argv) > 1:
6363
args = sys.argv[1:]
64-
run(args)
64+
sys.exit(run(args).returncode)
6565

6666

6767
if __name__ == "__main__":

tests/test_cli.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import os
44
import re
5-
from typing import TYPE_CHECKING
5+
import subprocess
6+
from unittest.mock import MagicMock, patch
67

7-
from openapi_generator_cli import run
8+
import pytest
89

9-
if TYPE_CHECKING:
10-
import pytest
10+
from openapi_generator_cli import cli, run
11+
12+
RETURN_CODE = 23
1113

1214

1315
def test_cli_version(capfd: pytest.CaptureFixture[str]) -> None:
@@ -45,3 +47,16 @@ def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
4547
"Found unexpected parameters: [--invalid-arg-404]"
4648
in captured.err.split(os.linesep)[0]
4749
)
50+
51+
52+
@patch("openapi_generator_cli.run", autospec=True)
53+
@patch("sys.argv", ["openapi-generator-cli", "version"])
54+
def test_cli_exits_with_returncode(run_mock: MagicMock) -> None:
55+
run_mock.return_value = subprocess.CompletedProcess(args=[], returncode=RETURN_CODE)
56+
57+
with pytest.raises(SystemExit) as exc_info:
58+
cli()
59+
60+
assert exc_info.value.code == RETURN_CODE
61+
62+
run_mock.assert_called_once_with(["version"])

0 commit comments

Comments
 (0)