summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pyrepl/test_pyrepl.py
diff options
context:
space:
mode:
authorThomas Grainger <tagrain@gmail.com>2025-01-22 12:48:33 (GMT)
committerGitHub <noreply@github.com>2025-01-22 12:48:33 (GMT)
commit24c84d816f2f2ecb76b80328c3f1d8c05ead0b10 (patch)
tree5522c3300c45d2bf2d25c9f89146e7d70748e101 /Lib/test/test_pyrepl/test_pyrepl.py
parenta16ded10ad3952406280be5ab9ff86a476867b08 (diff)
downloadcpython-24c84d816f2f2ecb76b80328c3f1d8c05ead0b10.zip
cpython-24c84d816f2f2ecb76b80328c3f1d8c05ead0b10.tar.gz
cpython-24c84d816f2f2ecb76b80328c3f1d8c05ead0b10.tar.bz2
gh-128770: fix ResourceWarning in test_pyrepl (#128906)
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
-rw-r--r--Lib/test/test_pyrepl/test_pyrepl.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 00dc990..3540d2a 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1324,22 +1324,21 @@ class TestMain(ReplTestCase):
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"])