Skip to content

Commit dd2fef5

Browse files
Yhg1smeta-codesync[bot]
authored andcommitted
Fix test_pickletools and test_pickle on GitHub CI.
Summary: In the test for _imp.create_builtin, restore the module's attributes after recreating the builtins, since otherwise we're left without __loader__ and __package__ and other attributes set by importlib, which breaks test_pickletools and test_pickle if they're run in the same process. Reviewed By: itamaro Differential Revision: D114275932 fbshipit-source-id: 7f3ef4b514f47f200a28dd4553a13d63a5a7f616
1 parent c13cda6 commit dd2fef5

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Lib/test/test_import/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,16 @@ class Spec2:
12631263

12641264
def test_create_builtin(self):
12651265
for internal_mod in (sys, builtins):
1266+
# _imp.create_builtin will nuke things like __loader__ and
1267+
# __package__, which are addded by importlib._bootstrap. Instead
1268+
# of trying to re-add them, just restore the old module
1269+
# contents if create_builtin returns the same module object.
1270+
mod_dict = internal_mod.__dict__.copy()
12661271
class Spec:
12671272
name = internal_mod.__name__
12681273

12691274
self.assertIs(_imp.create_builtin(Spec()), internal_mod)
1275+
internal_mod.__dict__.update(mod_dict)
12701276

12711277
class Spec:
12721278
name = "nonexistent_lib"

0 commit comments

Comments
 (0)