File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -652,6 +652,34 @@ def __init__(self, x):
652652
653653 self .assertEqual (set (weakset ), set ([depickled1 , depickled2 ]))
654654
655+ def test_ignoring_whichmodule_exception (self ):
656+ class FakeModule (object ):
657+ def __getattr__ (self , name ):
658+ # This throws an exception while looking up within
659+ # pickle.whichimodule.
660+ raise Exception ()
661+
662+ class Foo (object ):
663+ __module__ = None
664+
665+ def foo (self ):
666+ return "it works!"
667+
668+ def foo ():
669+ return "it works!"
670+
671+ foo .__module__ = None
672+
673+ sys .modules ["_fake_module" ] = FakeModule ()
674+ try :
675+ # Test whichmodule in save_global.
676+ self .assertEqual (pickle_depickle (Foo ()).foo (), "it works!" )
677+
678+ # Test whichmodule in save_function.
679+ self .assertEqual (pickle_depickle (foo )(), "it works!" )
680+ finally :
681+ sys .modules .pop ("_fake_module" , None )
682+
655683
656684if __name__ == '__main__' :
657685 unittest .main ()
You can’t perform that action at this time.
0 commit comments