From cf78a12e46ced68003263f4f43cee8fac720aa2c Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Sun, 31 Jan 2021 00:58:56 +0100 Subject: [PATCH] Show --check-status warning with --quiet as well. (#1026) Fixes #1028 --- CHANGELOG.rst | 3 ++- README.rst | 2 +- httpie/core.py | 2 +- tests/test_output.py | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d8411953..c47be9d6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,7 @@ This project adheres to `Semantic Versioning `_. `2.4.0-dev`_ (unreleased) ------------------------- - +* Show a ``--check-status`` warning with ``--quiet`` as well, not only when the output si redirected. (`#1026`_) * Fixed upload with ``--session`` (`#1020`_). * Fixed a missing blank line between request and response (`#1006`_). @@ -488,3 +488,4 @@ This project adheres to `Semantic Versioning `_. .. _#963: https://github.com/httpie/httpie/issues/963 .. _#1006: https://github.com/httpie/httpie/issues/1006 .. _#1020: https://github.com/httpie/httpie/issues/1020 +.. _#1026: https://github.com/httpie/httpie/issues/1026 diff --git a/README.rst b/README.rst index 47d65bcb..4abf6078 100644 --- a/README.rst +++ b/README.rst @@ -1292,7 +1292,7 @@ Quiet output ------------ ``--quiet`` redirects all output that would otherwise go to ``stdout`` -and ``stderr`` (except for error messages) to ``/dev/null``. +and ``stderr`` to ``/dev/null`` (except for errors and warnings). This doesn’t affect output to a file via ``--output`` or ``--download``. .. code-block:: bash diff --git a/httpie/core.py b/httpie/core.py index 3f46603e..c71edd2c 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -185,7 +185,7 @@ def program(args: argparse.Namespace, env: Environment) -> ExitStatus: final_response = message if args.check_status or downloader: exit_status = http_status_to_exit_status(http_status=message.status_code, follow=args.follow) - if not env.stdout_isatty and exit_status != ExitStatus.SUCCESS: + if exit_status != ExitStatus.SUCCESS and (not env.stdout_isatty or args.quiet): env.log_error(f'HTTP {message.raw.status} {message.raw.reason}', level='warning') write_message(requests_message=message, env=env, args=args, with_headers=with_headers, with_body=do_write_body) diff --git a/tests/test_output.py b/tests/test_output.py index 7510408a..d5b15e46 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -54,6 +54,21 @@ class TestQuietFlag: assert r == '' assert r.stderr == '' + def test_quiet_with_check_status_non_zero(self, httpbin): + r = http( + '--quiet', '--check-status', httpbin + '/status/500', + tolerate_error_exit_status=True, + ) + assert 'http: warning: HTTP 500' in r.stderr + + def test_quiet_with_check_status_non_zero_pipe(self, httpbin): + r = http( + '--quiet', '--check-status', httpbin + '/status/500', + tolerate_error_exit_status=True, + env=MockEnvironment(stdout_isatty=False) + ) + assert 'http: warning: HTTP 500' in r.stderr + @mock.patch('httpie.cli.argtypes.AuthCredentials._getpass', new=lambda self, prompt: 'password') def test_quiet_with_password_prompt(self, httpbin):