File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import os
44import re
5+ import shutil
56import subprocess
6- from unittest . mock import MagicMock , patch
7+ from typing import TYPE_CHECKING
78
8- import pytest
9+ from openapi_generator_cli import run
910
10- from openapi_generator_cli import cli , run
11-
12- RETURN_CODE = 23
11+ if TYPE_CHECKING :
12+ import pytest
1313
1414
1515def test_cli_version (capfd : pytest .CaptureFixture [str ]) -> None :
@@ -49,14 +49,8 @@ def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
4949 )
5050
5151
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" ])
52+ def test_cli_script_exits_with_returncode () -> None :
53+ cli_path = shutil .which ("openapi-generator-cli" )
54+ assert cli_path is not None
55+ result = subprocess .run ([cli_path , "this-is-invalid-subcommand" ], check = False ) # noqa: S603
56+ assert result .returncode == 1
You can’t perform that action at this time.
0 commit comments