From b89518988e81840942630553aed873a0cb6acdd6 Mon Sep 17 00:00:00 2001 From: Yuki Morikawa <193417531+Doyoubelieveinfate@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:54:11 +0900 Subject: [PATCH] Fix double quiet warnings with redirected output --- CHANGELOG.md | 4 ++++ httpie/context.py | 2 +- tests/test_output.py | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0497ac3508..77bb45b407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This document records all notable changes to [HTTPie](https://httpie.io). This project adheres to [Semantic Versioning](https://semver.org/). +## Unreleased + +- Fixed `-qq` leaking warnings when standard output is redirected. ([#1978](https://github.com/httpie/cli/issues/1978)) + ## [3.2.4](https://github.com/httpie/cli/compare/3.2.3...3.2.4) (2024-11-01) - Fix default certs loading and unpin `requests`. ([#1596](https://github.com/httpie/cli/issues/1596)) diff --git a/httpie/context.py b/httpie/context.py index 2a54f46916..fd7e7c6ecc 100644 --- a/httpie/context.py +++ b/httpie/context.py @@ -168,7 +168,7 @@ def as_silent(self) -> Iterator[None]: self.stderr = original_stderr def log_error(self, msg: str, level: LogLevel = LogLevel.ERROR) -> None: - if self.stdout_isatty and self.quiet >= LOG_LEVEL_DISPLAY_THRESHOLDS[level]: + if self.quiet >= LOG_LEVEL_DISPLAY_THRESHOLDS[level]: stderr = self.stderr # Not directly /dev/null, since stderr might be mocked else: stderr = self._orig_stderr diff --git a/tests/test_output.py b/tests/test_output.py index 2242177dbc..dbec8fc2e6 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -83,13 +83,15 @@ def test_quiet_quiet_with_check_status_non_zero(self, httpbin): ) assert not r.stderr - def test_quiet_quiet_with_check_status_non_zero_pipe(self, httpbin): + @pytest.mark.parametrize('quiet_flags', [('--quiet', '--quiet'), ('-qq',)]) + def test_quiet_quiet_with_check_status_non_zero_pipe(self, httpbin, quiet_flags): r = http( - '--quiet', '--quiet', '--check-status', httpbin + '/status/500', + *quiet_flags, '--check-status', httpbin + '/status/500', tolerate_error_exit_status=True, env=MockEnvironment(stdout_isatty=False) ) - assert 'http: warning: HTTP 500' in r.stderr + assert not r.stderr + assert r.exit_status == ExitStatus.ERROR_HTTP_5XX @mock.patch('httpie.core.program') @pytest.mark.parametrize('flags, expected_warnings', [ @@ -110,10 +112,12 @@ def warn_and_run(*args, **kwargs): assert len(record) == expected_warnings - def test_double_quiet_on_error(self, httpbin): + @pytest.mark.parametrize('stdout_isatty', [True, False]) + def test_double_quiet_on_error(self, httpbin, stdout_isatty): r = http( '-qq', '--check-status', '$$$this.does.not.exist$$$', tolerate_error_exit_status=True, + env=MockEnvironment(stdout_isatty=stdout_isatty), ) assert not r assert 'Couldn’t resolve the given hostname' in r.stderr