InsecureRequestWarning + pytest - PullRequest
       3

InsecureRequestWarning + pytest

1 голос
/ 04 июля 2019

У меня все еще есть предупреждение SSL о сводке pytest.
Python 2.7.5
requests==2.22.0
urllib3==1.25.3
pytest version 4.3.1

Это код:

import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def test_x():
  response = requests.get("https:// ...",
                          verify=False)
  print response.text

Вывод 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 ==========================================

Как удалить предупреждение SSL из pytest?

1 Ответ

1 голос
/ 04 июля 2019

Повторение комментария: Вы можете удалить , только включив проверку SSL-сертификата. Вы можете, однако, скрыть это (таким образом, предупреждение все еще отправляется, но не отображается в разделе предупреждений):

выбранные тесты

применение маркера pytest.mark.filterwarnings к тесту по классу предупреждения:

@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning')
def test_example_com():
    requests.get('https://www.example.com', verify=False)

или с помощью предупреждающего сообщения:

@pytest.mark.filterwarnings('ignore:Unverified HTTPS request is being made.*')
def test_example_com():
    requests.get('https://www.example.com', verify=False)

(разница между одинарным или двойным двоеточием в ignore:: и ignore:).

полный набор тестов

Настройте filterwarnings в pytest.ini, также с помощью класса предупреждения:

[pytest]
filterwarnings =
    ignore::urllib3.exceptions.InsecureRequestWarning

или с помощью предупреждающего сообщения:

[pytest]
filterwarnings =
    ignore:Unverified HTTPS request is being made.*
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...