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
Provenance
- Commit
005571d- Tree
6b5c3dc- Author
Nate Prewitt <nate.prewitt@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
d63e94f
4 files changed+28 added−27 removed
modified:tests/test_help.py+8 added-6 removed
1+from unittest import mock2+3 from requests.help import info4 5 6 def test_system_ssl():5 unmodified lines12 def __init__(self, version):13 self.__version__ = version14 15 14-def test_idna_without_version_attribute(mocker):16+def 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": ""}22 23 22-def test_idna_with_version_attribute(mocker):24+def 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 lines7 import os8 import pickle9 import re10 import warnings11+from unittest import mock12 13 import pytest14 import urllib315 from urllib3.util import Timeout as Urllib3Timeout956 unmodified lines972 "/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"] == expected983 984 def test_http_with_certificate(self, httpbin):985 r = requests.get(httpbin(), cert=".")478 unmodified lines1464 (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 lines2091 2092 next(r.iter_lines())2093 assert len(list(r.iter_lines())) == 32094 2096- 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()2105 2106 def test_proxy_auth(self):2107 adapter = HTTPAdapter()2108 headers = adapter.proxy_headers("http://user:pass@httpbin.org")689 unmodified linesmodified:tests/test_utils.py+5 added-4 removed
3 unmodified lines4 import tarfile5 import zipfile6 from collections import deque7 from io import BytesIO8+from unittest import mock9 10 import pytest11 12 from requests import compat738 unmodified lines751 ("http://user:pass@hostname", "hostname"),752 ("http://user:pass@hostname:5000", "hostname"),753 ),754 )754-def test_should_bypass_proxies_pass_only_hostname(url, expected, mocker):755+def 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)762 763 764 @pytest.mark.parametrize(765 "cookiejar",161 unmodified linesmodified:requirements-dev.txt-1 removed
1 -e .[socks]2 pytest>=2.8.0,<=6.2.53 pytest-cov4 pytest-httpbin==2.0.05-pytest-mock==2.0.05 httpbin==0.10.06 trustme7 wheel8 cryptography<40.0.0; python_version <= '3.7' and platform_python_implementation == 'PyPy'