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
Closed
Changes from all commits
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
4 changes: 3 additions & 1 deletion 4 Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def _save_and_remove_module(name, orig_modules):
"""
# try to import the module and raise an error if it can't be imported
if name not in sys.modules:
orig_modules = sys.modules.copy()
__import__(name)
del sys.modules[name]
sys.modules.clear()
sys.modules.update(orig_modules)
Comment on lines +245 to +246

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I considered this option, but some modules can not support re-importing. So it is safer to restore only explicitly mentioned modules and their submodules.
See #28654.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, sorry, Serhiy. I missed your PR :(

for modname in list(sys.modules):
if modname == name or modname.startswith(name + '.'):
orig_modules[modname] = sys.modules[modname]
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.