Skip to content

Commit

Permalink
Show --check-status warning with --quiet as well. (#1026)
Browse files Browse the repository at this point in the history
Fixes #1028
  • Loading branch information
jkbrzt authored Jan 30, 2021
1 parent 0f1e098 commit cf78a12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project adheres to `Semantic Versioning <https://semver.org/>`_.

`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`_).

Expand Down Expand Up @@ -488,3 +488,4 @@ This project adheres to `Semantic Versioning <https://semver.org/>`_.
.. _#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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion httpie/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def request_body_read_callback(chunk: bytes):
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)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ def test_quiet(self, httpbin, argument_name):
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):
Expand Down

0 comments on commit cf78a12

Please sign in to comment.