https://github.com/python/cpython/commit/67971cd605246ce4390cd56218aa4ae3366cb54e
commit: 67971cd605246ce4390cd56218aa4ae3366cb54e
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: pablogsal <[email protected]>
date: 2025-01-22T13:13:08Z
summary:
[3.13] gh-128770: fix ResourceWarning in test_pyrepl (GH-128906) (#129179)
files:
M Lib/test/test_pyrepl/test_pyrepl.py
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py
b/Lib/test/test_pyrepl/test_pyrepl.py
index 4ddf7e25465eeb..a20e79b674a916 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
if readline.backend != "editline":
self.skipTest("GNU readline is not affected by this issue")
- hfile = tempfile.NamedTemporaryFile()
- self.addCleanup(unlink, hfile.name)
- env = os.environ.copy()
- env["PYTHON_HISTORY"] = hfile.name
-
- env["PYTHON_BASIC_REPL"] = "1"
- output, exit_code = self.run_repl("spam \nexit()\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertIn("spam ", output)
- self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
- self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
-
- env.pop("PYTHON_BASIC_REPL", None)
- output, exit_code = self.run_repl("exit\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
+ with tempfile.NamedTemporaryFile() as hfile:
+ env = os.environ.copy()
+ env["PYTHON_HISTORY"] = hfile.name
+
+ env["PYTHON_BASIC_REPL"] = "1"
+ output, exit_code = self.run_repl("spam \nexit()\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertIn("spam ", output)
+ self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
+ self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
+
+ env.pop("PYTHON_BASIC_REPL", None)
+ output, exit_code = self.run_repl("exit\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]