def test_quiet_with_output_redirection(self, tmp_path, httpbin, quiet_flags, with_download):
        url = httpbin + '/robots.txt'
        output_path = Path('output.txt')
        env = MockEnvironment()
        orig_cwd = os.getcwd()
        output = requests.get(url).text
        extra_args = ['--download'] if with_download else []
        os.chdir(tmp_path)
        try:
            assert os.listdir('.') == []
            r = http(
                *quiet_flags,
                '--output', str(output_path),
                *extra_args,
                url,
                env=env
            )
            assert os.listdir('.') == [str(output_path)]
            assert r == ''
            assert r.stderr == ''
            assert env.stderr is env.devnull
            if with_download:
                assert env.stdout is env.devnull
            else:
                assert env.stdout is not env.devnull  # --output swaps stdout.
            assert output_path.read_text(encoding=UTF8) == output
        finally:
            os.chdir(orig_cwd)