@@ -843,15 +843,26 @@ def test_bracketed_paste_single_line(self):
843843class TestMain (TestCase ):
844844 @force_not_colorized
845845 def test_exposed_globals_in_repl (self ):
846- expected_output = (
847- "[\' __annotations__\' , \' __builtins__\' , \' __doc__\' , \' __loader__\' , "
848- "\' __name__\' , \' __package__\' , \' __spec__\' ]"
849- )
846+ pre = "['__annotations__', '__builtins__'"
847+ post = "'__loader__', '__name__', '__package__', '__spec__']"
850848 output , exit_code = self .run_repl (["sorted(dir())" , "exit" ])
851- if "can\ ' t use pyrepl" in output :
849+ if "can't use pyrepl" in output :
852850 self .skipTest ("pyrepl not available" )
853851 self .assertEqual (exit_code , 0 )
854- self .assertIn (expected_output , output )
852+
853+ # if `__main__` is not a file (impossible with pyrepl)
854+ case1 = f"{ pre } , '__doc__', { post } " in output
855+
856+ # if `__main__` is an uncached .py file (no .pyc)
857+ case2 = f"{ pre } , '__doc__', '__file__', { post } " in output
858+
859+ # if `__main__` is a cached .pyc file and the .py source exists
860+ case3 = f"{ pre } , '__cached__', '__doc__', '__file__', { post } " in output
861+
862+ # if `__main__` is a cached .pyc file but there's no .py source file
863+ case4 = f"{ pre } , '__cached__', '__doc__', { post } " in output
864+
865+ self .assertTrue (case1 or case2 or case3 or case4 , output )
855866
856867 def test_dumb_terminal_exits_cleanly (self ):
857868 env = os .environ .copy ()
0 commit comments