This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_zipimport_support mucks up with modules
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ncoghlan, pitrou
Priority: normal Keywords:

Created on 2010-11-27 23:21 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg122590 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-11-27 23:21
This test failure is due to test_zipimport_support loading and unloading modules, which leads to them being reloaded. Then the ssl.CertificateError which is checked for by assertRaises isn't the same as the one raised by the module under test (I have printed the type names and ids below):

$ ./python -E -bb -m test.regrtest test_http_cookies test_zipimport_support test_httplib
[1/3] test_http_cookies
[2/3] test_zipimport_support
[3/3] test_httplib
<class 'ssl.CertificateError'> 49243264
<class 'ssl.CertificateError'> 51134640
test test_httplib failed -- Traceback (most recent call last):
  File "/home/antoine/py3k/__svn__/Lib/test/test_httplib.py", line 481, in test_local_bad_hostname
    h.request('GET', '/')
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 950, in request
    self._send_request(method, url, body, headers)
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 988, in _send_request
    self.endheaders(body)
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 946, in endheaders
    self._send_output(message_body)
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 791, in _send_output
    self.send(msg)
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 737, in send
    self.connect()
  File "/home/antoine/py3k/__svn__/Lib/http/client.py", line 1096, in connect
    ssl.match_hostname(self.sock.getpeercert(), self.host)
  File "/home/antoine/py3k/__svn__/Lib/ssl.py", line 142, in match_hostname
    % (hostname, dnsnames[0]))
ssl.CertificateError: hostname 'localhost' doesn't match 'fakehostname'


(witnessed in http://www.python.org/dev/buildbot/all/builders/AMD64%20Snow%20Leopard%203.x/builds/527/steps/test/logs/stdio )
msg125988 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-01-11 09:32
Even more special: put a test_doctest in first and the attempt to clean up sys.modules in test_zipimport_support leaves things alone so the _ssl module doesn't break (test_doctest just leaves sys.modules alone and doesn't even try to remove all the modules it implicitly imports).

I'm actually tempted to remove test.support.modules_setup() and modules_cleanup() and delete the calls from the affected tests. Trying to clear out implicitly imported modules is going to create far more problems than it resolves.
msg125991 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-01-11 10:06
Fixed for 3.2 in r87925. (I simply dropped the attempt to restore sys.modules to its original state from test_zipimport_support)
msg126009 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-01-11 14:47
2.7 and 3.1 don't appear to exhibit the fault, so closing this one.
History
Date User Action Args
2022-04-11 14:57:09adminsetgithub: 54765
2011-01-11 14:47:44ncoghlansetstatus: open -> closed

messages: + msg126009
resolution: fixed
stage: needs patch -> resolved
2011-01-11 10:06:33ncoghlansetmessages: + msg125991
2011-01-11 09:32:26ncoghlansetmessages: + msg125988
2010-11-27 23:21:06pitroucreate