From c33535ba99f66f59d2e9230f33f8064da24fb160 Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Wed, 27 Feb 2019 11:04:06 +0000 Subject: [PATCH] Use caplog instead of mock --- tests/unit/test_index_html_page.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_index_html_page.py b/tests/unit/test_index_html_page.py index 16ea4beadaf..debcbf0eb68 100644 --- a/tests/unit/test_index_html_page.py +++ b/tests/unit/test_index_html_page.py @@ -118,8 +118,7 @@ def test_get_html_response_no_head(url): ] -@mock.patch("pip._internal.index.logger") -def test_get_html_response_dont_log_clear_text_password(m_logger): +def test_get_html_response_dont_log_clear_text_password(caplog): """ `_get_html_response()` shouldn't send a HEAD request if the URL does not look like an archive, only the GET request that retrieves data. @@ -133,11 +132,17 @@ def test_get_html_response_dont_log_clear_text_password(m_logger): "get.return_value": "text/html", })) + caplog.set_level(logging.DEBUG) + resp = _get_html_response(url_template.format(password), session=session) assert resp is not None - assert m_logger.debug.mock_calls == [ - mock.call("Getting page %s", url_template.format("****")) + + assert len(caplog.records) == 1 + record = caplog.records[0] + assert record.levelname == 'DEBUG' + assert record.message.splitlines() == [ + "Getting page {}".format(url_template.format("****")), ]