Ezio Melotti added the comment: > ./python -m test -v test_codecencodings_kr test_imp test_codeccallbacks
Thanks, I was trying to reproduce the failure yesterday with test_imp test_codeccallbacks but it wasn't working -- now I can reproduce it. My idea was to import html and html.parser and then remove them both, and that's what the patch did: >>> import sys >>> m = set(sys.modules) >>> from html import parser >>> set(sys.modules) - m {'html.parser', 'linecache', 'tokenize', 'warnings', '_markupbase', 'html', 'token'} >>> del sys.modules['html'] >>> set(sys.modules) - m {'html.parser', 'linecache', 'tokenize', '_markupbase', 'warnings', 'token'} >>> del sys.modules['html.parser'] >>> set(sys.modules) - m {'token', '_markupbase', 'tokenize', 'warnings', 'linecache'} I think the problem is that if test_codecencodings_kr is run before test_imp, test_imp deletes html and html.parser but leaves the html.entities imported by test_codecencodings_kr, and when test_codeccallbacks tries to use it again it fails: >>> import sys >>> m = set(sys.modules) >>> import html.entities >>> set(sys.modules) - m {'html.entities', 'html'} >>> from html import parser >>> set(sys.modules) - m {'_markupbase', 'html', 'html.entities', 'tokenize', 'html.parser', 'linecache', 'warnings', 'token'} >>> del sys.modules['html'] >>> set(sys.modules) - m {'_markupbase', 'tokenize', 'html.entities', 'token', 'html.parser', 'linecache', 'warnings'} >>> del sys.modules['html.parser'] >>> set(sys.modules) - m {'_markupbase', 'tokenize', 'html.entities', 'token', 'linecache', 'warnings'} >>> html.entities <module 'html.entities' from '/home/wolf/dev/py/py3k/Lib/html/entities.py'> >>> import html.entities >>> html.entities Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'entities' A solution would be to remove all the modules that start with 'html.' (see attached patch): >>> import sys >>> m = set(sys.modules) >>> import html.entities >>> from html import parser >>> del sys.modules['html'] >>> del sys.modules['html.parser'] >>> set(sys.modules) - m {'warnings', 'linecache', 'token', 'html.entities', 'tokenize', '_markupbase'} >>> del sys.modules['html.entities'] >>> import html.entities >>> html.entities <module 'html.entities' from '/home/wolf/dev/py/py3k/Lib/html/entities.py'> Another (possibly better) solution would be to copy sys.modules before messing with it and restore it afterwards. I was looking in test.support for a context manager to do it but I didn't find it, so I just deleted the modules I imported manually. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18706> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com