1414 SuppressCrashReport ,
1515 SHORT_TIMEOUT ,
1616)
17- from test .support .script_helper import kill_python
17+ from test .support .script_helper import kill_python , EnsureSafeUserHistory
1818from test .support .import_helper import import_module
1919
2020try :
@@ -71,7 +71,7 @@ def run_on_interactive_mode(source):
7171
7272
7373@support .force_not_colorized_test_class
74- class TestInteractiveInterpreter (unittest .TestCase ):
74+ class TestInteractiveInterpreter (EnsureSafeUserHistory , unittest .TestCase ):
7575
7676 @cpython_only
7777 # Python built with Py_TRACE_REFS fail with a fatal error in
@@ -303,42 +303,44 @@ def test_asyncio_repl_reaches_python_startup_script(self):
303303
304304 @unittest .skipUnless (pty , "requires pty" )
305305 def test_asyncio_repl_is_ok (self ):
306- m , s = pty .openpty ()
307- cmd = [sys .executable , "-I" , "-m" , "asyncio" ]
308- env = os .environ .copy ()
309- proc = subprocess .Popen (
310- cmd ,
311- stdin = s ,
312- stdout = s ,
313- stderr = s ,
314- text = True ,
315- close_fds = True ,
316- env = env ,
317- )
318- os .close (s )
319- os .write (m , b"await asyncio.sleep(0)\n " )
320- os .write (m , b"exit()\n " )
321- output = []
322- while select .select ([m ], [], [], SHORT_TIMEOUT )[0 ]:
323- try :
324- data = os .read (m , 1024 ).decode ("utf-8" )
325- if not data :
306+ with os_helper .temp_dir () as tmpdir :
307+ m , s = pty .openpty ()
308+ cmd = [sys .executable , "-m" , "asyncio" ]
309+ env = os .environ .copy ()
310+ env ["PYTHON_HISTORY" ] = os .path .join (tmpdir , ".asyncio_history" )
311+ proc = subprocess .Popen (
312+ cmd ,
313+ stdin = s ,
314+ stdout = s ,
315+ stderr = s ,
316+ text = True ,
317+ close_fds = True ,
318+ env = env ,
319+ )
320+ os .close (s )
321+ os .write (m , b"await asyncio.sleep(0)\n " )
322+ os .write (m , b"exit()\n " )
323+ output = []
324+ while select .select ([m ], [], [], SHORT_TIMEOUT )[0 ]:
325+ try :
326+ data = os .read (m , 1024 ).decode ("utf-8" )
327+ if not data :
328+ break
329+ except OSError :
326330 break
327- except OSError :
328- break
329- output .append (data )
330- os .close (m )
331- try :
332- exit_code = proc .wait (timeout = SHORT_TIMEOUT )
333- except subprocess .TimeoutExpired :
334- proc .kill ()
335- exit_code = proc .wait ()
331+ output .append (data )
332+ os .close (m )
333+ try :
334+ exit_code = proc .wait (timeout = SHORT_TIMEOUT )
335+ except subprocess .TimeoutExpired :
336+ proc .kill ()
337+ exit_code = proc .wait ()
336338
337- self .assertEqual (exit_code , 0 , "" .join (output ))
339+ self .assertEqual (exit_code , 0 , "" .join (output ))
338340
339341
340342@support .force_not_colorized_test_class
341- class TestInteractiveModeSyntaxErrors (unittest .TestCase ):
343+ class TestInteractiveModeSyntaxErrors (EnsureSafeUserHistory , unittest .TestCase ):
342344
343345 def test_interactive_syntax_error_correct_line (self ):
344346 output = run_on_interactive_mode (dedent ("""\
@@ -356,7 +358,7 @@ def f():
356358 self .assertEqual (traceback_lines , expected_lines )
357359
358360
359- class TestAsyncioREPL (unittest .TestCase ):
361+ class TestAsyncioREPL (EnsureSafeUserHistory , unittest .TestCase ):
360362 def test_multiple_statements_fail_early (self ):
361363 user_input = "1 / 0; print(f'afterwards: {1+1}')"
362364 p = spawn_repl ("-m" , "asyncio" )
0 commit comments