Package: requests
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu kinetic ubuntu-patch

Dear Maintainer,

When moving from 2.25.1+dfsg to 2.27.1+dfsg, we enabled the pytest
test-suite in autopkgtest.

Some of the tests fail when HTTP proxy variables are set:

FAILED 
tests/test_requests.py::TestRequests::test_errors[http://doesnotexist.google.com-ConnectionError]
FAILED 
tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_self_prepared_request
FAILED 
tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_session_prepared_request
FAILED 
tests/test_requests.py::TestRequests::test_respect_proxy_env_on_send_with_redirects
FAILED tests/test_requests.py::TestRequests::test_respect_proxy_env_on_get - ...
FAILED tests/test_requests.py::TestRequests::test_respect_proxy_env_on_request


*** /tmp/tmp877wny2v/bug_body

In Ubuntu, the attached patch was applied to achieve the following:

  * Fix autopkgtest when http_proxy, https_proxy or no_proxy variable is set
    (LP: #1974182)


Thanks for considering the patch.


-- System Information:
Debian Release: bookworm/sid
  APT prefers jammy-updates
  APT policy: (500, 'jammy-updates'), (500, 'jammy-security'), (500, 'jammy')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.15.0-30-generic (SMP w/4 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru 
requests-2.27.1+dfsg/debian/patches/0002-Fix-tests-with-HTTP-proxy.patch 
requests-2.27.1+dfsg/debian/patches/0002-Fix-tests-with-HTTP-proxy.patch
--- requests-2.27.1+dfsg/debian/patches/0002-Fix-tests-with-HTTP-proxy.patch    
1970-01-01 01:00:00.000000000 +0100
+++ requests-2.27.1+dfsg/debian/patches/0002-Fix-tests-with-HTTP-proxy.patch    
2022-05-19 14:14:07.000000000 +0200
@@ -0,0 +1,83 @@
+Description: Fix autopkgtest when HTTP/HTTPS proxy is set
+ The pytest suite does not expect the http_proxy, https_proxy and no_proxy
+ variables to be present in the environment. They make pytest fail and
+ therefore autopkgtest fail as well.
+Author: Olivier Gayot <olivier.ga...@canonical.com>
+Bug: <URL to the upstream bug report if any, implies patch has been forwarded, 
optional>
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/requests/+bug/1974182
+Forwarded: no
+Last-Update: 2022-05-19
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: b/tests/test_requests.py
+===================================================================
+--- a/tests/test_requests.py   2022-01-05 16:35:04.000000000 +0100
++++ b/tests/test_requests.py   2022-05-19 14:13:08.454208318 +0200
+@@ -535,8 +535,9 @@
+             ('http://fe80::5054:ff:fe5a:fc0', InvalidURL)
+         ))
+     def test_errors(self, url, exception):
+-        with pytest.raises(exception):
+-            requests.get(url, timeout=1)
++        with override_environ(http_proxy=None, https_proxy=None):
++            with pytest.raises(exception):
++                requests.get(url, timeout=1)
+ 
+     def test_proxy_error(self):
+         # any proxy related error (address resolution, no route to host, etc) 
should result in a ProxyError
+@@ -557,14 +558,14 @@
+             requests.get(httpbin(), proxies={'http': 
'http:///example.com:8080'})
+ 
+     def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):
+-        with override_environ(http_proxy=INVALID_PROXY):
++        with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
+             with pytest.raises(ProxyError):
+                 session = requests.Session()
+                 request = requests.Request('GET', httpbin())
+                 session.send(request.prepare())
+ 
+     def test_respect_proxy_env_on_send_session_prepared_request(self, 
httpbin):
+-        with override_environ(http_proxy=INVALID_PROXY):
++        with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
+             with pytest.raises(ProxyError):
+                 session = requests.Session()
+                 request = requests.Request('GET', httpbin())
+@@ -572,7 +573,7 @@
+                 session.send(prepared)
+ 
+     def test_respect_proxy_env_on_send_with_redirects(self, httpbin):
+-        with override_environ(http_proxy=INVALID_PROXY):
++        with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
+             with pytest.raises(ProxyError):
+                 session = requests.Session()
+                 url = httpbin('redirect/1')
+@@ -581,13 +582,13 @@
+                 session.send(request.prepare())
+ 
+     def test_respect_proxy_env_on_get(self, httpbin):
+-        with override_environ(http_proxy=INVALID_PROXY):
++        with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
+             with pytest.raises(ProxyError):
+                 session = requests.Session()
+                 session.get(httpbin())
+ 
+     def test_respect_proxy_env_on_request(self, httpbin):
+-        with override_environ(http_proxy=INVALID_PROXY):
++        with override_environ(no_proxy=None, http_proxy=INVALID_PROXY):
+             with pytest.raises(ProxyError):
+                 session = requests.Session()
+                 session.request(method='GET', url=httpbin())
+Index: b/tests/utils.py
+===================================================================
+--- a/tests/utils.py   2022-01-05 16:35:04.000000000 +0100
++++ b/tests/utils.py   2022-05-19 14:11:28.470186792 +0200
+@@ -9,7 +9,8 @@
+     save_env = dict(os.environ)
+     for key, value in kwargs.items():
+         if value is None:
+-            del os.environ[key]
++            with contextlib.suppress(KeyError):
++                del os.environ[key]
+         else:
+             os.environ[key] = value
+     try:
diff -Nru requests-2.27.1+dfsg/debian/patches/series 
requests-2.27.1+dfsg/debian/patches/series
--- requests-2.27.1+dfsg/debian/patches/series  2022-03-20 17:51:34.000000000 
+0100
+++ requests-2.27.1+dfsg/debian/patches/series  2022-05-19 14:10:52.000000000 
+0200
@@ -1 +1,2 @@
 0001-Remove-remote-images-traking-code-and-ads.patch
+0002-Fix-tests-with-HTTP-proxy.patch

Reply via email to