Skip to content

Couldn't disable INFO, DEBUG logs of the lib that is used in a test method (for example requests/urllib3) #3604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
7artur7 opened this issue Jun 20, 2018 · 4 comments
Labels
plugin: logging related to the logging builtin plugin

Comments

@7artur7
Copy link

7artur7 commented Jun 20, 2018

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

@pytestbot pytestbot added the plugin: logging related to the logging builtin plugin label Jun 20, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #753 (Missing example test), #1599 (Ability to disable capture from within a test), #3125 (Incremental testing from example in documentation), and #1527 (show deselected info after collected info and before test execution).

@7artur7 7artur7 changed the title [Question] How to disable INFO, DEBUG logs of the lib that is used in a test method (for example requests/urllib3) Couldn't disable INFO, DEBUG logs of the lib that is used in a test method (for example requests/urllib3) Jun 21, 2018
@IgorZotkin
Copy link

+1

@7artur7
Copy link
Author

7artur7 commented Jun 22, 2018

Found problem on my side, got additional logs inside of file that was imported into conftes.

@7artur7 7artur7 closed this as completed Jun 22, 2018
@alonroth
Copy link

@7artur7 I'm facing the same problem.
Can you elaborate on how you managed to overcome this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: logging related to the logging builtin plugin
Projects
None yet
Development

No branches or pull requests

4 participants