Debian Codegraph @

debian/patches/0002-Fix-tests-with-HTTP-proxy.patch

raw
1 From: Olivier Gayot <[email protected]>
2 Date: Thu, 13 Jun 2024 09:56:35 +0100
3 Subject: Fix autopkgtest when HTTP/HTTPS proxy is set
4
5 The pytest suite does not expect the http_proxy, https_proxy and no_proxy
6 variables to be present in the environment. They make pytest fail and
7 therefore autopkgtest fail as well.
8
9 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/requests/+bug/1974182
10 Forwarded: no
11 Last-Update: 2022-05-19
12 ---
13 tests/test_requests.py | 15 ++++++++-------
14 tests/utils.py | 3 ++-
15 2 files changed, 10 insertions(+), 8 deletions(-)
16
17 diff --git a/tests/test_requests.py b/tests/test_requests.py
18 index 571535f..6683cfc 100644
19 --- a/tests/test_requests.py
20 +++ b/tests/test_requests.py
21 @@ -591,8 +591,9 @@ class TestRequests:
22 ),
23 )
24 def test_errors(self, url, exception):
25 - with pytest.raises(exception):
26 - requests.get(url, timeout=1)
27 + with override_environ(http_proxy=None, https_proxy=None):
28 + with pytest.raises(exception):
29 + requests.get(url, timeout=1)
30
31 def test_proxy_error(self):
32 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError
33 @@ -615,14 +616,14 @@ class TestRequests:
34 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})
35
36 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):
37 - with override_environ(http_proxy=INVALID_PROXY):
38 + with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
39 with pytest.raises(ProxyError):
40 session = requests.Session()
41 request = requests.Request("GET", httpbin())
42 session.send(request.prepare())
43
44 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):
45 - with override_environ(http_proxy=INVALID_PROXY):
46 + with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
47 with pytest.raises(ProxyError):
48 session = requests.Session()
49 request = requests.Request("GET", httpbin())
50 @@ -630,7 +631,7 @@ class TestRequests:
51 session.send(prepared)
52
53 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):
54 - with override_environ(http_proxy=INVALID_PROXY):
55 + with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
56 with pytest.raises(ProxyError):
57 session = requests.Session()
58 url = httpbin("redirect/1")
59 @@ -639,13 +640,13 @@ class TestRequests:
60 session.send(request.prepare())
61
62 def test_respect_proxy_env_on_get(self, httpbin):
63 - with override_environ(http_proxy=INVALID_PROXY):
64 + with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
65 with pytest.raises(ProxyError):
66 session = requests.Session()
67 session.get(httpbin())
68
69 def test_respect_proxy_env_on_request(self, httpbin):
70 - with override_environ(http_proxy=INVALID_PROXY):
71 + with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
72 with pytest.raises(ProxyError):
73 session = requests.Session()
74 session.request(method="GET", url=httpbin())
75 diff --git a/tests/utils.py b/tests/utils.py
76 index 6cb75bf..7871a32 100644
77 --- a/tests/utils.py
78 +++ b/tests/utils.py
79 @@ -7,7 +7,8 @@ def override_environ(**kwargs):
80 save_env = dict(os.environ)
81 for key, value in kwargs.items():
82 if value is None:
83 - del os.environ[key]
84 + with contextlib.suppress(KeyError):
85 + del os.environ[key]
86 else:
87 os.environ[key] = value
88 try: