Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

test_pkgutil should clean up spam module #123780

Copy link
Copy link
@encukou

Description

@encukou
Issue body actions

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.

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixestestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.