@@ -68,6 +68,16 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, custom=F
6868spawn_asyncio_repl = partial (spawn_repl , "-m" , "asyncio" , custom = True )
6969
7070
71+ @contextmanager
72+ def new_startup_env (* , code : str , histfile : str = ".pythonhist" ):
73+ """Create temporary environment variables for a PYTHONSTARTUP script."""
74+ with os_helper .temp_dir () as tmpdir :
75+ filename = os .path .join (tmpdir , "pythonstartup.py" )
76+ with open (filename , "w" ) as f :
77+ f .write (os .linesep .join (code .splitlines ()))
78+ yield {"PYTHONSTARTUP" : filename , "PYTHON_HISTORY" : os .path .join (tmpdir , histfile )}
79+
80+
7181def run_on_interactive_mode (source ):
7282 """Spawn a new Python interpreter, pass the given
7383 input source code from the stdin and return the
@@ -310,15 +320,6 @@ def test_asyncio_repl_is_ok(self):
310320 self .assertEqual (exit_code , 0 , "" .join (output ))
311321
312322
313- @contextmanager
314- def new_startup_env (* , code : str , histfile : str = ".pythonhist" ):
315- with os_helper .temp_dir () as tmpdir :
316- filename = os .path .join (tmpdir , "pythonstartup.py" )
317- with open (filename , "w" ) as f :
318- f .write (os .linesep .join (code .splitlines ()))
319- yield {"PYTHONSTARTUP" : filename , "PYTHON_HISTORY" : os .path .join (tmpdir , histfile )}
320-
321-
322323@support .force_not_colorized_test_class
323324class TestInteractiveModeSyntaxErrors (unittest .TestCase ):
324325
0 commit comments