Skip to content

Commit b3ed3d4

Browse files
committed
Document new_startup_env
1 parent a774da5 commit b3ed3d4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Lib/test/test_repl.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, custom=F
6868
spawn_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+
7181
def 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
323324
class TestInteractiveModeSyntaxErrors(unittest.TestCase):
324325

0 commit comments

Comments
 (0)