Remove pytest-mock requirement (#6505)

This commit is contained in:
Nate Prewitt
2023-08-13 16:08:21 -07:00
committed by GitHub
parent d63e94f552
commit 005571d118
4 changed files with 28 additions and 27 deletions
-1
View File
@@ -2,7 +2,6 @@
pytest>=2.8.0,<=6.2.5
pytest-cov
pytest-httpbin==2.0.0
pytest-mock==2.0.0
httpbin==0.10.0
trustme
wheel
+8 -6
View File
@@ -1,3 +1,5 @@
from unittest import mock
from requests.help import info
@@ -11,15 +13,15 @@ class VersionedPackage:
self.__version__ = version
def test_idna_without_version_attribute(mocker):
def test_idna_without_version_attribute():
"""Older versions of IDNA don't provide a __version__ attribute, verify
that if we have such a package, we don't blow up.
"""
mocker.patch("requests.help.idna", new=None)
assert info()["idna"] == {"version": ""}
with mock.patch("requests.help.idna", new=None):
assert info()["idna"] == {"version": ""}
def test_idna_with_version_attribute(mocker):
def test_idna_with_version_attribute():
"""Verify we're actually setting idna version when it should be available."""
mocker.patch("requests.help.idna", new=VersionedPackage("2.6"))
assert info()["idna"] == {"version": "2.6"}
with mock.patch("requests.help.idna", new=VersionedPackage("2.6")):
assert info()["idna"] == {"version": "2.6"}
+15 -16
View File
@@ -8,6 +8,7 @@ import os
import pickle
import re
import warnings
from unittest import mock
import pytest
import urllib3
@@ -972,12 +973,12 @@ class TestRequests:
),
),
)
def test_env_cert_bundles(self, httpbin, mocker, env, expected):
def test_env_cert_bundles(self, httpbin, env, expected):
s = requests.Session()
mocker.patch("os.environ", env)
settings = s.merge_environment_settings(
url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None
)
with mock.patch("os.environ", env):
settings = s.merge_environment_settings(
url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None
)
assert settings["verify"] == expected
def test_http_with_certificate(self, httpbin):
@@ -1464,11 +1465,9 @@ class TestRequests:
(urllib3.exceptions.SSLError, tuple(), RequestsSSLError),
),
)
def test_iter_content_wraps_exceptions(
self, httpbin, mocker, exception, args, expected
):
def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):
r = requests.Response()
r.raw = mocker.Mock()
r.raw = mock.Mock()
# ReadTimeoutError can't be initialized by mock
# so we'll manually create the instance with args
r.raw.stream.side_effect = exception(*args)
@@ -2093,16 +2092,16 @@ class TestRequests:
next(r.iter_lines())
assert len(list(r.iter_lines())) == 3
def test_session_close_proxy_clear(self, mocker):
def test_session_close_proxy_clear(self):
proxies = {
"one": mocker.Mock(),
"two": mocker.Mock(),
"one": mock.Mock(),
"two": mock.Mock(),
}
session = requests.Session()
mocker.patch.dict(session.adapters["http://"].proxy_manager, proxies)
session.close()
proxies["one"].clear.assert_called_once_with()
proxies["two"].clear.assert_called_once_with()
with mock.patch.dict(session.adapters["http://"].proxy_manager, proxies):
session.close()
proxies["one"].clear.assert_called_once_with()
proxies["two"].clear.assert_called_once_with()
def test_proxy_auth(self):
adapter = HTTPAdapter()
+5 -4
View File
@@ -5,6 +5,7 @@ import tarfile
import zipfile
from collections import deque
from io import BytesIO
from unittest import mock
import pytest
@@ -751,13 +752,13 @@ def test_should_bypass_proxies(url, expected, monkeypatch):
("http://user:pass@hostname:5000", "hostname"),
),
)
def test_should_bypass_proxies_pass_only_hostname(url, expected, mocker):
def test_should_bypass_proxies_pass_only_hostname(url, expected):
"""The proxy_bypass function should be called with a hostname or IP without
a port number or auth credentials.
"""
proxy_bypass = mocker.patch("requests.utils.proxy_bypass")
should_bypass_proxies(url, no_proxy=None)
proxy_bypass.assert_called_once_with(expected)
with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:
should_bypass_proxies(url, no_proxy=None)
proxy_bypass.assert_called_once_with(expected)
@pytest.mark.parametrize(