Repository navigation
Closed
Description
When running the tests with --randomize, as is done by the buildbots, @mhsmith came across this failure:
======================================================================
ERROR: test_find_class (test.test_pickle.CUnpicklerTests.test_find_class)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/msmith/git/python/cpython/Lib/test/pickletester.py", line 1265, in test_find_class
self.assertRaises(ModuleNotFoundError, unpickler.find_class, 'spam', 'log')
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/unittest/case.py", line 804, in assertRaises
return context.handle('assertRaises', args, kwargs)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/unittest/case.py", line 238, in handle
callable_obj(*args, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
AttributeError: module 'spam' has no attribute 'log'
======================================================================
ERROR: test_find_class (test.test_pickle.PyUnpicklerTests.test_find_class)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/msmith/git/python/cpython/Lib/test/pickletester.py", line 1265, in test_find_class
self.assertRaises(ModuleNotFoundError, unpickler.find_class, 'spam', 'log')
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/unittest/case.py", line 804, in assertRaises
return context.handle('assertRaises', args, kwargs)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/unittest/case.py", line 238, in handle
callable_obj(*args, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pickle.py", line 1620, in find_class
return getattr(sys.modules[module], name)
AttributeError: module 'spam' has no attribute 'log'
----------------------------------------------------------------------
Ran 857 tests in 2.954s
FAILED (errors=2, skipped=31)
test test_pickle failed
This can be reproduced by running only test_pkgutil and test_pickle, in that order. test_pkgutil leaves behind a spam module in sys.modules, while test_pickle assumes there is no such module.
Activity
gh-123780: Make test_pkgutil clean up `spam` module (GH-123036)
pythongh-123780: Make test_pkgutil clean up `spam` module (pythonGH-1…
pythongh-123780: Make test_pkgutil clean up `spam` module (pythonGH-1…
Wulian233 commentedon Sep 6, 2024
I see that this PR has been merged and used
pkgutil.getloader. Will remove in Python 3.14See #119656
https://github.com/python/cpython/blob/main/Lib/pkgutil.py#L273-L276
encukou commentedon Sep 6, 2024
Sorry for creating a conflict!
picnixz commentedon Sep 6, 2024
It's fine, my PR is not pressing. I'm used to deal with conflicts on my PRs xD
[3.13] gh-123780: Make test_pkgutil clean up `spam` module (GH-123036) (
[3.12] gh-123780: Make test_pkgutil clean up `spam` module (GH-123036) (