Skip to content

gh-108927: Fix test_import + test_importlib + test_unittest problem #108929

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

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/test/test_unittest/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pickle
from test import support
from test.support import import_helper
import test.test_importlib.util
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why such standard import triggers a bug. Maybe give a try to test.bisect_cmd to isolate exactly which tests are the bare minimum to trigger it.


import unittest
import unittest.mock
Expand Down Expand Up @@ -826,6 +825,8 @@ def restore():
'as dotted module names')

def test_discovery_failed_discovery(self):
from test.test_importlib import util

loader = unittest.TestLoader()
package = types.ModuleType('package')

Expand All @@ -837,7 +838,7 @@ def _import(packagename, *args, **kwargs):
# Since loader.discover() can modify sys.path, restore it when done.
with import_helper.DirsOnSysPath():
# Make sure to remove 'package' from sys.modules when done.
with test.test_importlib.util.uncache('package'):
with util.uncache('package'):
with self.assertRaises(TypeError) as cm:
loader.discover('package')
self.assertEqual(str(cm.exception),
Expand Down