GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `test_pkgutil` should clean up `spam` module · Issue #123780 · python/cpython

test_pkgutil should clean up spam module #123780

New issue
Copy link
New issue
Copy link
Closed
Closed
test_pkgutil should clean up spam module#123780
Copy link
Labels
3.12only security fixesonly security fixes3.13only security fixesonly 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

Description

@encukou
encukou
opened on Sep 6, 2024
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

  • gh-123780: Make test_pkgutil clean up spam module #123036
  • [3.13] gh-123780: Make test_pkgutil clean up spam module (GH-123036) #123781
  • [3.12] gh-123780: Make test_pkgutil clean up spam module (GH-123036) #123782

Activity

  1. encukou
    added a commit that references this issue on Sep 6, 2024

    gh-123780: Make test_pkgutil clean up `spam` module (GH-123036)

    eca3fe4
  2. miss-islington
    added 2 commits that reference this issue on Sep 6, 2024

    pythongh-123780: Make test_pkgutil clean up `spam` module (pythonGH-1…

    6405a6a

    pythongh-123780: Make test_pkgutil clean up `spam` module (pythonGH-1…

    81cfee7
  3. Eclips4
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    testsTests in the Lib/test dirTests in the Lib/test dir
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Sep 6, 2024
  4. Wulian233 commented on Sep 6, 2024

    @Wulian233
    Wulian233
    on Sep 6, 2024
    Contributor
    More actions

    I see that this PR has been merged and used pkgutil.getloader. Will remove in Python 3.14

    See #119656

    https://github.com/python/cpython/blob/main/Lib/pkgutil.py#L273-L276

    Reacted by Petr Viktorin and Wulian233
  5. encukou commented on Sep 6, 2024

    @encukou
    encukou
    on Sep 6, 2024
    MemberAuthor
    More actions

    Sorry for creating a conflict!

  6. picnixz commented on Sep 6, 2024

    @picnixz
    picnixz
    on Sep 6, 2024
    Member
    More actions

    Sorry for creating a conflict!

    It's fine, my PR is not pressing. I'm used to deal with conflicts on my PRs xD

  7. Yhg1s
    added a commit that references this issue on Sep 6, 2024

    [3.13] gh-123780: Make test_pkgutil clean up `spam` module (GH-123036) (

    72cdd2a
  8. encukou
    added a commit that references this issue on Sep 9, 2024

    [3.12] gh-123780: Make test_pkgutil clean up `spam` module (GH-123036) (

    349cc27
  9. encukou
    closed this as completedon Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixes3.13only security fixesonly 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.