@@ -586,19 +586,15 @@ def test_getsource_on_code_object(self):
586586 self .assertSourceEqual (mod .eggs .__code__ , 12 , 18 )
587587
588588class TestGetsourceInteractive (unittest .TestCase ):
589- def tearDown (self ):
590- mod .ParrotDroppings .__module__ = self .mod
591- sys .modules ['__main__' ] = self .main
592-
593589 def test_getclasses_interactive (self ):
594- self . main = sys . modules [ '__main__' ]
595- self . mod = mod . ParrotDroppings . __module__
596- class MockModule :
597- __file__ = None
598- sys . modules [ '__main__' ] = MockModule
599- mod . ParrotDroppings . __module__ = '__main__'
600- with self . assertRaisesRegex ( OSError , 'source code not available' ) as e :
601- inspect . getsource ( mod . ParrotDroppings )
590+ # bpo-44648: simulate a REPL session;
591+ # there is no `__file__` in the __main__ module
592+ code = "import sys, inspect; \
593+ assert not hasattr(sys.modules['__main__'], '__file__'); \
594+ A = type('A', (), {}); \
595+ inspect.getsource(A)"
596+ _ , _ , stderr = assert_python_failure ( "-c" , code , __isolated = True )
597+ self . assertIn ( b'OSError: source code not available' , stderr )
602598
603599class TestGettingSourceOfToplevelFrames (GetSourceBase ):
604600 fodderModule = mod
0 commit comments