Skip to content
Myr

Remove pytest-mock requirement (#6505)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent d63e94f · Browse files · 4 files+28 added−27 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+28 added−27 removed

  • tests:+28 added−26 removed
  • other:+0 added−1 removed

4 files+28 added−27 removed

modified:tests/test_help.py+8 added-6 removed
1from unittest import mock23from requests.help import info456def test_system_ssl():
5 unmodified lines
12 def __init__(self, version):13 self.__version__ = version141514def test_idna_without_version_attribute(mocker):16def test_idna_without_version_attribute():17 """Older versions of IDNA don't provide a __version__ attribute, verify18 that if we have such a package, we don't blow up.19 """18 mocker.patch("requests.help.idna", new=None)19 assert info()["idna"] == {"version": ""}20 with mock.patch("requests.help.idna", new=None):21 assert info()["idna"] == {"version": ""}222322def test_idna_with_version_attribute(mocker):24def test_idna_with_version_attribute():25 """Verify we're actually setting idna version when it should be available."""24 mocker.patch("requests.help.idna", new=VersionedPackage("2.6"))25 assert info()["idna"] == {"version": "2.6"}26 with mock.patch("requests.help.idna", new=VersionedPackage("2.6")):27 assert info()["idna"] == {"version": "2.6"}
modified:tests/test_requests.py+15 added-16 removed
6 unmodified lines
7import os8import pickle9import re10import warnings11from unittest import mock1213import pytest14import urllib315from urllib3.util import Timeout as Urllib3Timeout
956 unmodified lines
972 "/curl/path",973 ),974 ),975 )975 def test_env_cert_bundles(self, httpbin, mocker, env, expected):976 def test_env_cert_bundles(self, httpbin, env, expected):977 s = requests.Session()977 mocker.patch("os.environ", env)978 settings = s.merge_environment_settings(979 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None980 )978 with mock.patch("os.environ", env):979 settings = s.merge_environment_settings(980 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None981 )982 assert settings["verify"] == expected983984 def test_http_with_certificate(self, httpbin):985 r = requests.get(httpbin(), cert=".")
478 unmodified lines
1464 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),1465 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),1466 ),1467 )1467 def test_iter_content_wraps_exceptions(1468 self, httpbin, mocker, exception, args, expected1469 ):1468 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):1469 r = requests.Response()1471 r.raw = mocker.Mock()1470 r.raw = mock.Mock()1471 # ReadTimeoutError can't be initialized by mock1472 # so we'll manually create the instance with args1473 r.raw.stream.side_effect = exception(*args)1474
616 unmodified lines
20912092 next(r.iter_lines())2093 assert len(list(r.iter_lines())) == 320942096 def test_session_close_proxy_clear(self, mocker):2095 def test_session_close_proxy_clear(self):2096 proxies = {2098 "one": mocker.Mock(),2099 "two": mocker.Mock(),2097 "one": mock.Mock(),2098 "two": mock.Mock(),2099 }2100 session = requests.Session()2102 mocker.patch.dict(session.adapters["http://"].proxy_manager, proxies)2103 session.close()2104 proxies["one"].clear.assert_called_once_with()2105 proxies["two"].clear.assert_called_once_with()2101 with mock.patch.dict(session.adapters["http://"].proxy_manager, proxies):2102 session.close()2103 proxies["one"].clear.assert_called_once_with()2104 proxies["two"].clear.assert_called_once_with()21052106 def test_proxy_auth(self):2107 adapter = HTTPAdapter()2108 headers = adapter.proxy_headers("http://user:pass@httpbin.org")
689 unmodified lines
modified:tests/test_utils.py+5 added-4 removed
3 unmodified lines
4import tarfile5import zipfile6from collections import deque7from io import BytesIO8from unittest import mock910import pytest1112from requests import compat
738 unmodified lines
751 ("http://user:pass@hostname", "hostname"),752 ("http://user:pass@hostname:5000", "hostname"),753 ),754)754def test_should_bypass_proxies_pass_only_hostname(url, expected, mocker):755def test_should_bypass_proxies_pass_only_hostname(url, expected):756 """The proxy_bypass function should be called with a hostname or IP without757 a port number or auth credentials.758 """758 proxy_bypass = mocker.patch("requests.utils.proxy_bypass")759 should_bypass_proxies(url, no_proxy=None)760 proxy_bypass.assert_called_once_with(expected)759 with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:760 should_bypass_proxies(url, no_proxy=None)761 proxy_bypass.assert_called_once_with(expected)762763764@pytest.mark.parametrize(765 "cookiejar",
161 unmodified lines
modified:requirements-dev.txt-1 removed
1-e .[socks]2pytest>=2.8.0,<=6.2.53pytest-cov4pytest-httpbin==2.0.05pytest-mock==2.0.05httpbin==0.10.06trustme7wheel8cryptography<40.0.0; python_version <= '3.7' and platform_python_implementation == 'PyPy'