@@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
13241324 if readline .backend != "editline" :
13251325 self .skipTest ("GNU readline is not affected by this issue" )
13261326
1327- hfile = tempfile .NamedTemporaryFile ()
1328- self .addCleanup (unlink , hfile .name )
1329- env = os .environ .copy ()
1330- env ["PYTHON_HISTORY" ] = hfile .name
1331-
1332- env ["PYTHON_BASIC_REPL" ] = "1"
1333- output , exit_code = self .run_repl ("spam \n exit()\n " , env = env )
1334- self .assertEqual (exit_code , 0 )
1335- self .assertIn ("spam " , output )
1336- self .assertNotEqual (pathlib .Path (hfile .name ).stat ().st_size , 0 )
1337- self .assertIn ("spam\\ 040" , pathlib .Path (hfile .name ).read_text ())
1338-
1339- env .pop ("PYTHON_BASIC_REPL" , None )
1340- output , exit_code = self .run_repl ("exit\n " , env = env )
1341- self .assertEqual (exit_code , 0 )
1342- self .assertNotIn ("\\ 040" , pathlib .Path (hfile .name ).read_text ())
1327+ with tempfile .NamedTemporaryFile () as hfile :
1328+ env = os .environ .copy ()
1329+ env ["PYTHON_HISTORY" ] = hfile .name
1330+
1331+ env ["PYTHON_BASIC_REPL" ] = "1"
1332+ output , exit_code = self .run_repl ("spam \n exit()\n " , env = env )
1333+ self .assertEqual (exit_code , 0 )
1334+ self .assertIn ("spam " , output )
1335+ self .assertNotEqual (pathlib .Path (hfile .name ).stat ().st_size , 0 )
1336+ self .assertIn ("spam\\ 040" , pathlib .Path (hfile .name ).read_text ())
1337+
1338+ env .pop ("PYTHON_BASIC_REPL" , None )
1339+ output , exit_code = self .run_repl ("exit\n " , env = env )
1340+ self .assertEqual (exit_code , 0 )
1341+ self .assertNotIn ("\\ 040" , pathlib .Path (hfile .name ).read_text ())
13431342
13441343 def test_keyboard_interrupt_after_isearch (self ):
13451344 output , exit_code = self .run_repl (["\x12 " , "\x03 " , "exit" ])
0 commit comments