Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-123780: Make test_pkgutil clean up spam module #123036

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

mhsmith
Copy link
Member

@mhsmith mhsmith commented Aug 15, 2024

When running the tests with --randomize, as is done by the buildbots, I 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.

@encukou
Copy link
Member

encukou commented Sep 6, 2024

PRs that need backporting should not skip issue; the issue number helps keep related PRs grouped together.

@encukou encukou changed the title Make test_pkgutil clean up spam module gh-123780: Make test_pkgutil clean up spam module Sep 6, 2024
@encukou encukou merged commit eca3fe4 into python:main Sep 6, 2024
41 checks passed
@miss-islington-app
Copy link

Thanks @mhsmith for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 6, 2024
…23036)

(cherry picked from commit eca3fe4)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 6, 2024

GH-123781 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 6, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 6, 2024
…23036)

(cherry picked from commit eca3fe4)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 6, 2024

GH-123782 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Sep 6, 2024
Yhg1s pushed a commit that referenced this pull request Sep 6, 2024
#123781)

gh-123780: Make test_pkgutil clean up `spam` module (GH-123036)
(cherry picked from commit eca3fe4)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
encukou pushed a commit that referenced this pull request Sep 9, 2024
GH-123782)

(cherry picked from commit eca3fe4)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
@mhsmith
Copy link
Member Author

mhsmith commented Sep 11, 2024

PRs that need backporting should not skip issue; the issue number helps keep related PRs grouped together.

OK, I'll remember that. But doesn't the original PR provide enough grouping already? It links to the backports, and the backports link to it.

@encukou
Copy link
Member

encukou commented Sep 12, 2024

Well, not as clearly as the issue's Linked PRs section :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants