@@ -2272,39 +2272,47 @@ def test_nonencodable_module_name_error(self):
22722272
22732273 def test_nested_lookup_error (self ):
22742274 # Nested name does not exist
2275- obj = REX ('AbstractPickleTests.spam' )
2275+ global TestGlobal
2276+ class TestGlobal :
2277+ class A :
2278+ pass
2279+ obj = REX ('TestGlobal.A.B.C' )
22762280 obj .__module__ = __name__
22772281 for proto in protocols :
22782282 with self .subTest (proto = proto ):
22792283 with self .assertRaises (pickle .PicklingError ) as cm :
22802284 self .dumps (obj , proto )
22812285 self .assertEqual (str (cm .exception ),
22822286 f"Can't pickle { obj !r} : "
2283- f"it's not found as { __name__ } .AbstractPickleTests.spam " )
2287+ f"it's not found as { __name__ } .TestGlobal.A.B.C " )
22842288 self .assertEqual (str (cm .exception .__context__ ),
2285- "type object 'AbstractPickleTests ' has no attribute 'spam '" )
2289+ "type object 'A ' has no attribute 'B '" )
22862290
22872291 obj .__module__ = None
22882292 for proto in protocols :
22892293 with self .subTest (proto = proto ):
22902294 with self .assertRaises (pickle .PicklingError ) as cm :
22912295 self .dumps (obj , proto )
22922296 self .assertEqual (str (cm .exception ),
2293- f"Can't pickle { obj !r} : it's not found as __main__.AbstractPickleTests.spam" )
2297+ f"Can't pickle { obj !r} : "
2298+ f"it's not found as __main__.TestGlobal.A.B.C" )
22942299 self .assertEqual (str (cm .exception .__context__ ),
2295- "module '__main__' has no attribute 'AbstractPickleTests '" )
2300+ "module '__main__' has no attribute 'TestGlobal '" )
22962301
22972302 def test_wrong_object_lookup_error (self ):
22982303 # Name is bound to different object
2299- obj = REX ('AbstractPickleTests' )
2304+ global TestGlobal
2305+ class TestGlobal :
2306+ pass
2307+ obj = REX ('TestGlobal' )
23002308 obj .__module__ = __name__
2301- AbstractPickleTests .ham = []
23022309 for proto in protocols :
23032310 with self .subTest (proto = proto ):
23042311 with self .assertRaises (pickle .PicklingError ) as cm :
23052312 self .dumps (obj , proto )
23062313 self .assertEqual (str (cm .exception ),
2307- f"Can't pickle { obj !r} : it's not the same object as { __name__ } .AbstractPickleTests" )
2314+ f"Can't pickle { obj !r} : "
2315+ f"it's not the same object as { __name__ } .TestGlobal" )
23082316 self .assertIsNone (cm .exception .__context__ )
23092317
23102318 obj .__module__ = None
@@ -2313,9 +2321,10 @@ def test_wrong_object_lookup_error(self):
23132321 with self .assertRaises (pickle .PicklingError ) as cm :
23142322 self .dumps (obj , proto )
23152323 self .assertEqual (str (cm .exception ),
2316- f"Can't pickle { obj !r} : it's not found as __main__.AbstractPickleTests" )
2324+ f"Can't pickle { obj !r} : "
2325+ f"it's not found as __main__.TestGlobal" )
23172326 self .assertEqual (str (cm .exception .__context__ ),
2318- "module '__main__' has no attribute 'AbstractPickleTests '" )
2327+ "module '__main__' has no attribute 'TestGlobal '" )
23192328
23202329 def test_local_lookup_error (self ):
23212330 # Test that whichmodule() errors out cleanly when looking up
0 commit comments