diff --git a/src/packaged/cli.py b/src/packaged/cli.py index d369217..cc675c7 100644 --- a/src/packaged/cli.py +++ b/src/packaged/cli.py @@ -70,7 +70,8 @@ def cli(argv: list[str] | None = None) -> int: parser.add_argument( "--quiet", help="Disable all output", - action="store_false" if "CI" in os.environ else "store_true", + action="store_true", + default="CI" in os.environ, ) args = parser.parse_args(argv) config = Config(**vars(args)) diff --git a/tests/cli_test.py b/tests/cli_test.py index 8aae6bf..58da223 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -1,12 +1,15 @@ from __future__ import annotations +import os from unittest import mock +from pytest import MonkeyPatch + import packaged import packaged.cli -def test_cli() -> None: +def test_cli(monkeypatch: MonkeyPatch) -> None: """Ensures that CLI passes args to `create_package()` properly.""" with mock.patch.object(packaged.cli, "create_package") as mocked: packaged.cli.cli(["./foo", "pip install foo", "python -m foo"]) @@ -68,3 +71,33 @@ def test_cli() -> None: packaged.DEFAULT_PYTHON_VERSION, True, ) + + # Test --quiet when CI is true, regardless of if the flag is passed + monkeypatch.setattr(os, "environ", {"CI": "1"}) + with mock.patch.object(packaged.cli, "create_package") as mocked: + packaged.cli.cli(["./some", "pip install some", "python some.py", "./some.bin"]) + + # quiet is True + mocked.assert_called_with( + mock.ANY, + "./some", + "pip install some", + "python some.py", + packaged.DEFAULT_PYTHON_VERSION, + True, + ) + monkeypatch.setattr(os, "environ", {"CI": "1"}) + with mock.patch.object(packaged.cli, "create_package") as mocked: + packaged.cli.cli( + ["./some", "pip install some", "python some.py", "./some.bin", "--quiet"] + ) + + # quiet is True + mocked.assert_called_with( + mock.ANY, + "./some", + "pip install some", + "python some.py", + packaged.DEFAULT_PYTHON_VERSION, + True, + )