@@ -69,13 +69,16 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, custom=F
6969
7070
7171@contextmanager
72- def new_startup_env (* , code : str , histfile : str = ".pythonhist" ):
72+ def new_pythonstartup_env (* , code : str , histfile : str = ".pythonhist" ):
7373 """Create environment variables for a PYTHONSTARTUP script in a temporary directory."""
7474 with os_helper .temp_dir () as tmpdir :
7575 filename = os .path .join (tmpdir , "pythonstartup.py" )
7676 with open (filename , "w" ) as f :
7777 f .write ('\n ' .join (code .splitlines ()))
78- yield {"PYTHONSTARTUP" : filename , "PYTHON_HISTORY" : os .path .join (tmpdir , histfile )}
78+ yield {
79+ "PYTHONSTARTUP" : filename ,
80+ "PYTHON_HISTORY" : os .path .join (tmpdir , histfile )
81+ }
7982
8083
8184def run_on_interactive_mode (source ):
@@ -369,7 +372,8 @@ def test_pythonstartup_success(self):
369372 # errors based on https://github.com/python/cpython/issues/137576
370373 # case 1: error in user input, but PYTHONSTARTUP is fine
371374 startup_code = "print('notice from pythonstartup')"
372- startup_env = self .enterContext (new_startup_env (code = startup_code ))
375+ startup_env = self .enterContext (new_pythonstartup_env (code = startup_code ))
376+
373377 # -q to suppress noise
374378 p = spawn_repl ("-q" , env = os .environ | startup_env , isolated = False )
375379 p .stdin .write ("1/0" )
@@ -389,7 +393,8 @@ def test_pythonstartup_success(self):
389393 def test_pythonstartup_failure (self ):
390394 # case 2: error in PYTHONSTARTUP triggered by user input
391395 startup_code = "def foo():\n 1/0\n "
392- startup_env = self .enterContext (new_startup_env (code = startup_code ))
396+ startup_env = self .enterContext (new_pythonstartup_env (code = startup_code ))
397+
393398 # -q to suppress noise
394399 p = spawn_repl ("-q" , env = os .environ | startup_env , isolated = False )
395400 p .stdin .write ("foo()" )
@@ -479,7 +484,9 @@ def test_quiet_mode(self):
479484
480485 def test_pythonstartup_success (self ):
481486 startup_code = "import sys\n print('notice from pythonstartup in asyncio repl', file=sys.stderr)"
482- startup_env = self .enterContext (new_startup_env (code = startup_code , histfile = ".asyncio_history" ))
487+ startup_env = self .enterContext (
488+ new_pythonstartup_env (code = startup_code , histfile = ".asyncio_history" ))
489+
483490 p = spawn_asyncio_repl (env = os .environ | startup_env , stderr = subprocess .PIPE , isolated = False )
484491 p .stdin .write ("1/0" )
485492 kill_python (p )
@@ -503,7 +510,9 @@ def test_pythonstartup_success(self):
503510
504511 def test_pythonstartup_failure (self ):
505512 startup_code = "def foo():\n 1/0\n "
506- startup_env = self .enterContext (new_startup_env (code = startup_code , histfile = ".asyncio_history" ))
513+ startup_env = self .enterContext (
514+ new_pythonstartup_env (code = startup_code , histfile = ".asyncio_history" ))
515+
507516 p = spawn_asyncio_repl (env = os .environ | startup_env , stderr = subprocess .PIPE , isolated = False )
508517 p .stdin .write ("foo()" )
509518 kill_python (p )
0 commit comments