You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Introduce a mode to suppress all warnings (#1283)
This commit is contained in:
@@ -5,6 +5,7 @@ from unittest import mock
|
||||
import json
|
||||
import os
|
||||
import io
|
||||
import warnings
|
||||
from urllib.request import urlopen
|
||||
|
||||
import pytest
|
||||
@@ -90,6 +91,31 @@ class TestQuietFlag:
|
||||
)
|
||||
assert 'http: warning: HTTP 500' in r.stderr
|
||||
|
||||
@mock.patch('httpie.core.program')
|
||||
@pytest.mark.parametrize('flags, expected_warnings', [
|
||||
([], 1),
|
||||
(['-q'], 1),
|
||||
(['-qq'], 0),
|
||||
])
|
||||
def test_quiet_on_python_warnings(self, test_patch, httpbin, flags, expected_warnings):
|
||||
def warn_and_run(*args, **kwargs):
|
||||
warnings.warn('warning!!')
|
||||
return ExitStatus.SUCCESS
|
||||
|
||||
test_patch.side_effect = warn_and_run
|
||||
with pytest.warns(None) as record:
|
||||
http(*flags, httpbin + '/get')
|
||||
|
||||
assert len(record) == expected_warnings
|
||||
|
||||
def test_double_quiet_on_error(self, httpbin):
|
||||
r = http(
|
||||
'-qq', '--check-status', '$$$this.does.not.exist$$$',
|
||||
tolerate_error_exit_status=True,
|
||||
)
|
||||
assert not r
|
||||
assert 'Couldn’t resolve the given hostname' in r.stderr
|
||||
|
||||
@pytest.mark.parametrize('quiet_flags', QUIET_SCENARIOS)
|
||||
@mock.patch('httpie.cli.argtypes.AuthCredentials._getpass',
|
||||
new=lambda self, prompt: 'password')
|
||||
|
@@ -5,6 +5,7 @@ import sys
|
||||
import time
|
||||
import json
|
||||
import tempfile
|
||||
import warnings
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional, Union, List, Iterable
|
||||
@@ -96,6 +97,7 @@ class MockEnvironment(Environment):
|
||||
def cleanup(self):
|
||||
self.stdout.close()
|
||||
self.stderr.close()
|
||||
warnings.resetwarnings()
|
||||
if self._delete_config_dir:
|
||||
assert self._temp_dir in self.config_dir.parents
|
||||
from shutil import rmtree
|
||||
|
Reference in New Issue
Block a user