Hey.
Consider next example:
import requests
class TestSomething:
def test_methoder(self):
requests.get("http://google.com")
assert 1 == 2
when i launch it i see INFO, DEBUG logs from urllib3
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): google.com
send: b'GET / HTTP/1.1\r\nHost: google.com\r\nUser-Agent: python-requests/2.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: /\r\nConnection: keep-alive\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'
DEBUG:requests.packages.urllib3.connectionpool:"GET / HTTP/1.1" 301 219
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): www.google.com
header: Location header: Content-Type header: Date header: Expires header: Cache-Control header: Server header: Content-Length header: X-XSS-Protection header: X-Frame-Options send: b'GET / HTTP/1.1\r\nHost: www.google.com\r\nUser-Agent: python-requests/2.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: /\r\nConnection: keep-alive\r\n\r\n'
DEBUG:requests.packages.urllib3.connectionpool:"GET / HTTP/1.1" 200 5211
reply: 'HTTP/1.1 200 OK\r\n'
header: Date header: Expires header: Cache-Control header: Content-Type header: P3P header: Content-Encoding header: Server header: Content-Length header: X-XSS-Protection header: X-Frame-Options header: Set-Cookie header: Set-Cookie F
How can i disable it for tests?
I've tried increasing log level of the lib. Add this to the top of the file:
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
but I still see logs in Terminal.
I've tried to handle it with caplog:
def test_methoder(self, caplog):
caplog.set_level(logging.WARNING, logger='urllib3')
requests.get("http://google.com")
assert 1 == 2
but still same result.
Is there a way to completely remove this logs? The only info i need to see in Terminal in my case is an assertion error:
def test_methoder(self, caplog):
caplog.set_level(logging.WARNING, logger='urllib3')
requests.get("http://google.com")
assert 1 == 2
E assert 1 == 2
I don't need logs of the request methods, statuses etc.
pip list
allure-pytest 2.4.1
allure-python-commons 2.4.1
apipkg 1.4
atomicwrites 1.1.5
attrs 18.1.0
colorama 0.3.7
configparser 3.5.0
crayons 0.1.2
deepdiff 3.3.0
dpath 1.4.0
enum34 1.1.6
execnet 1.5.0
Faker 0.7.11
jsonpickle 0.9.6
jsonschema 2.6.0
lxml 4.2.1
more-itertools 4.2.0
namedlist 1.7
numpy 1.11.2
phonenumbers 7.7.3
pip 10.0.1
pluggy 0.6.0
py 1.5.3
pytest 3.6.1
pytest-forked 0.2
pytest-xdist 1.22.2
python-dateutil 2.5.3
requests 2.11.1
setuptools 39.2.0
six 1.10.0
urllib3 1.20
wheel 0.31.1
pytest 3.6.1 Mac OS 10.13.2
Hey.
Consider next example:
when i launch it i see
INFO,DEBUGlogs from urllib3How can i disable it for tests?
I've tried increasing log level of the lib. Add this to the top of the file:
but I still see logs in Terminal.
I've tried to handle it with
caplog:but still same result.
Is there a way to completely remove this logs? The only info i need to see in Terminal in my case is an assertion error:
I don't need logs of the request methods, statuses etc.
pip listpytest 3.6.1 Mac OS 10.13.2