[New-bugs-announce] [issue12124] python -m test test_packaging test_zipimport failure

STINNER Victor report at bugs.python.org
Thu May 19 22:42:05 CEST 2011

New submission from STINNER Victor <victor.stinner at haypocalc.com>:

"python -m test test_packaging test_zipimport" fails with:

FAIL: testAFakeZlib (test.test_zipimport.CompressedZipImportTestCase)
Traceback (most recent call last):
  File "/home/haypo/prog/HG/cpython/Lib/test/test_zipimport.py", line 130, in testAFakeZlib
    self.fail("expected test to raise ImportError")
AssertionError: expected test to raise ImportError

The problem is that the zipimport module keeps a reference to zlib.decompress() which "makes zlib.decompress immortal": see get_decompress_func() in zipimport.c.

Attached patch replaces the borrowed reference by a classic reference to allow to unload zlib.

I don't think that it makes zipimport slower: it calls PyImport_ImportModuleNoBlock("io") and PyObject_GetAttrString(zlib, "decompress") each time instead of just once, but PyImport_ImportModuleNoBlock() is just a lookup in a dict (if the zlib module is not unloaded between two calls to get_data()).

components: Extension Modules, Tests
files: zipimport_get_data.patch
keywords: patch
messages: 136334
nosy: haypo, tarek
priority: normal
severity: normal
status: open
title: python -m test test_packaging test_zipimport failure
versions: Python 3.3
Added file: http://bugs.python.org/file22033/zipimport_get_data.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list