Skip to content

Commit ef22044

Browse files
committed
prevent altering PYTHON_HISTORY file when running REPL tests
1 parent 48d0d0d commit ef22044

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_repl(
6868
try:
6969
return self._run_repl(
7070
repl_input,
71-
env=env,
71+
env=os.environ.copy() if env is None else env,
7272
cmdline_args=cmdline_args,
7373
cwd=cwd,
7474
skip=skip,
@@ -83,7 +83,7 @@ def _run_repl(
8383
self,
8484
repl_input: str | list[str],
8585
*,
86-
env: dict | None,
86+
env: dict[str, str],
8787
cmdline_args: list[str] | None,
8888
cwd: str,
8989
skip: bool,
@@ -93,11 +93,14 @@ def _run_repl(
9393
assert pty
9494
master_fd, slave_fd = pty.openpty()
9595
cmd = [sys.executable, "-i", "-u"]
96-
if env is None:
97-
cmd.append("-I")
98-
elif "PYTHON_HISTORY" not in env:
96+
if "PYTHON_HISTORY" not in env:
9997
env["PYTHON_HISTORY"] = os.path.join(cwd, ".regrtest_history")
10098
if cmdline_args is not None:
99+
if "PYTHON_HISTORY" in env:
100+
self.assertNotIn(
101+
"-I", cmdline_args,
102+
"PYTHON_HISTORY will be ignored by -I"
103+
)
101104
cmd.extend(cmdline_args)
102105

103106
try:
@@ -118,7 +121,7 @@ def _run_repl(
118121
cwd=cwd,
119122
text=True,
120123
close_fds=True,
121-
env=env if env else os.environ,
124+
env=env,
122125
)
123126
os.close(slave_fd)
124127
if isinstance(repl_input, list):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent altering the content of the :envvar:`PYTHON_HISTORY` file after
2+
running REPL tests. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)