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.

Title: test_codecs fails when ran after test_zipimport and test_mailbox.
Type: behavior Stage: patch review
Components: Tests Versions: Python 3.1, Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, amaury.forgeotdarc, pitrou, r.david.murray
Priority: normal Keywords: patch

Created on 2009-07-23 03:04 by alexandre.vassalotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit alexandre.vassalotti, 2009-07-23 03:12 This test case does _not_ trigger the bug. alexandre.vassalotti, 2009-07-23 03:13 This test case triggers the bug. alexandre.vassalotti, 2009-07-23 03:17 Pruned version of; this triggers the bug. alexandre.vassalotti, 2009-07-23 03:17 Pruned version of; this triggers the bug.
modcleanup.patch pitrou, 2009-11-13 01:57
Messages (6)
msg90837 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-07-23 03:04
For some yet unknown reason, test_codecs fails when it is run after
test_zipimport and subsequently test_mailbox:

./python Lib/test/ -w test_zipimport test_mailbox test_codecs
ERROR: test_basics (test.test_codecs.BasicUnicodeTest)
Traceback (most recent call last):
  File "/home/alex/src/", line
1360, in test_basics
    encodedresult += encoder.encode(c)
  File "/home/alex/src/", line 22,
in encode
    return codecs.ascii_encode(input, self.errors)[0]
AttributeError: 'NoneType' object has no attribute 'ascii_encode'

ERROR: test_decoder_state (test.test_codecs.BasicUnicodeTest)
Traceback (most recent call last):
  File "/home/alex/src/", line
1445, in test_decoder_state
    self.check_state_handling_decode(encoding, u, u.encode(encoding))
  File "/home/alex/src/", line
30, in check_state_handling_decode
    part1 = d.decode(s[:i])
  File "/home/alex/src/", line 26,
in decode
    return codecs.ascii_decode(input, self.errors)[0]
AttributeError: 'NoneType' object has no attribute 'ascii_decode'

Ran 121 tests in 0.204s

FAILED (errors=2)
test test_codecs failed -- errors occurred; run in verbose mode for details
msg90844 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-07-23 13:35
When the zipimport test is run, encodings.ascii is imported.  Then it is
removed from sys.modules by the test cleanup.  When the mailbox test is
run, it is reimported.  However, when the codecs test tries to use it,
the encodings.ascii module has been finalized (as if during interpreter
shutdown) by having all its globals set to None.  Thus the test failure.

I haven't figured out why this is happening yet, but it seems likely
that the issue is either with zipimport or with the zipimport test
cleanup.  I'm guessing that anything that triggers encodings.ascii to be
loaded before test_codecs tries to use it will trigger the bug, but I
haven't tested that theory yet.
msg90846 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-07-23 13:59
A simple solution could be to import encodings.ascii in,
before it saves the list of modules.

Or, since codecs are stored in a global cache dictionary that cannot be
cleared (interp->codec_search_cache), avoid unloading modules from the
encodings package.
msg95171 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-11-13 01:56
Here is a patch.
msg95172 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-11-13 02:04
The patch looks good to me.
msg95185 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-11-13 16:32
Thanks. The patch is now committed in py3k and 3.1.
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50800
2009-11-13 16:32:18pitrousetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg95185
2009-11-13 02:04:48alexandre.vassalottisetresolution: accepted
messages: + msg95172
2009-11-13 01:57:07pitrousetfiles: + modcleanup.patch
keywords: + patch
2009-11-13 01:56:31pitrousetnosy: + pitrou

messages: + msg95171
stage: needs patch -> patch review
2009-07-23 13:59:26amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg90846
2009-07-23 13:35:54r.david.murraysetnosy: + r.david.murray

messages: + msg90844
versions: + Python 3.1
2009-07-23 03:17:45alexandre.vassalottisetfiles: +
2009-07-23 03:17:06alexandre.vassalottisetfiles: +
2009-07-23 03:13:27alexandre.vassalottisetfiles: +
2009-07-23 03:12:18alexandre.vassalottisetfiles: +
2009-07-23 03:04:32alexandre.vassalotticreate