I still have the SSL warning on pytest summary.Python 2.7.5
requests==2.22.0
urllib3==1.25.3
pytest version 4.3.1
This is the code:
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def test_x():
response = requests.get("https:// ...",
verify=False)
print response.text
The output pytest mytest.py:
....
==================================================== warnings summary ====================================================
prova.py::test_x
/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================================== 1 passed, 1 warnings in 0.30 seconds ==========================================
How can i remove the SSL warning from pytest?
Use warnings. filterwarnings() to ignore deprecation warnings Call warnings. filterwarnings(action, category=DeprecationWarning) with action as "ignore" and category set to DeprecationWarning to ignore any deprecation warnings that may rise.
From https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings: InsecureRequestWarning. This happens when a request is made to an HTTPS URL without certificate verification enabled. Follow the certificate verification guide to resolve this warning.
Restating the comment: You can remove it only by turning the SSL cert verification back on. You can, however, hide it (so the warning is still emitted, but not displayed in the warnings section):
applying the pytest.mark.filterwarnings marker to a test, either by warning class:
@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning')
def test_example_com():
requests.get('https://www.example.com', verify=False)
or by warning message:
@pytest.mark.filterwarnings('ignore:Unverified HTTPS request is being made.*')
def test_example_com():
requests.get('https://www.example.com', verify=False)
(the difference is between single or double colons in ignore::
and ignore:
).
Configure filterwarnings
in the pytest.ini
, also either by warning class:
[pytest]
filterwarnings =
ignore::urllib3.exceptions.InsecureRequestWarning
or by warning message:
[pytest]
filterwarnings =
ignore:Unverified HTTPS request is being made.*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With