mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
fix(test): avoid impact of system proxies on urllib test suite by mocking relevant functions
Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
parent
9a87ce8b57
commit
4669c445cb
3 changed files with 18 additions and 5 deletions
|
|
@ -7,6 +7,7 @@
|
|||
import email.message
|
||||
import io
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from test import support
|
||||
from test.support import os_helper
|
||||
from test.support import socket_helper
|
||||
|
|
@ -86,9 +87,15 @@ def fakehttp(self, fakedata, mock_close=False):
|
|||
fake_http_class = fakehttp(fakedata, mock_close=mock_close)
|
||||
self._connection_class = http.client.HTTPConnection
|
||||
http.client.HTTPConnection = fake_http_class
|
||||
# Disable proxies during the test
|
||||
self.getproxies = unittest.mock.patch.object(urllib.request, 'getproxies', return_value={})
|
||||
self.getproxies.start()
|
||||
# Clear cached opener
|
||||
urllib.request.install_opener(None)
|
||||
|
||||
def unfakehttp(self):
|
||||
http.client.HTTPConnection = self._connection_class
|
||||
self.getproxies.stop()
|
||||
|
||||
|
||||
class urlopen_FileTests(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue