Skip to content

Commit 0023d5b

Browse files
authored
gh-152132: Close stderr_copy in test_api.test_run (#153591)
Previously, the test was leaking a file descriptor.
1 parent bbd1f2f commit 0023d5b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

Lib/test/test_capi/test_run.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,15 @@ def check_run_interactive(self, run, encode_filename, use_loop=False):
310310
# supported". In this case, run the test without redirecting
311311
# stderr to a temporary file.
312312
self._check_run_interactive(run, encode_filename, use_loop)
313-
else:
314-
with tempfile.TemporaryFile() as tmp:
315-
try:
316-
os.dup2(tmp.fileno(), STDERR_FD)
317-
self._check_run_interactive(run, encode_filename, use_loop)
318-
finally:
319-
os.dup2(stderr_copy, STDERR_FD)
313+
return
314+
315+
with tempfile.TemporaryFile() as tmp:
316+
try:
317+
os.dup2(tmp.fileno(), STDERR_FD)
318+
self._check_run_interactive(run, encode_filename, use_loop)
319+
finally:
320+
os.dup2(stderr_copy, STDERR_FD)
321+
os.close(stderr_copy)
320322

321323
def test_run_interactiveone(self):
322324
# Test PyRun_InteractiveOne()

0 commit comments

Comments
 (0)