@@ -326,13 +326,18 @@ def _futurize_test_script(self, filename='mytestscript.py', stages=(1, 2),
326326 try :
327327 output = check_output (call_args , stderr = STDOUT , env = self .env )
328328 except CalledProcessError as e :
329- msg = ('Error running the command %s\n %s\n Contents of file %s:\n \n %s' %
330- (' ' .join (call_args ),
331- 'env=%s' % self .env ,
332- fn ,
333- '----\n %s\n ----' % open (fn ).read (),
334- )
335- )
329+ with open (fn ) as f :
330+ msg = (
331+ 'Error running the command %s\n '
332+ '%s\n '
333+ 'Contents of file %s:\n '
334+ '\n '
335+ '%s' ) % (
336+ ' ' .join (call_args ),
337+ 'env=%s' % self .env ,
338+ fn ,
339+ '----\n %s\n ----' % f .read (),
340+ )
336341 ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError )
337342 raise ErrorClass (msg , e .returncode , e .cmd , output = e .output )
338343 return output
@@ -345,13 +350,18 @@ def _run_test_script(self, filename='mytestscript.py',
345350 output = check_output ([interpreter , fn ],
346351 env = self .env , stderr = STDOUT )
347352 except CalledProcessError as e :
348- msg = ('Error running the command %s\n %s\n Contents of file %s:\n \n %s' %
349- (' ' .join ([interpreter , fn ]),
350- 'env=%s' % self .env ,
351- fn ,
352- '----\n %s\n ----' % open (fn ).read (),
353- )
354- )
353+ with open (fn ) as f :
354+ msg = (
355+ 'Error running the command %s\n '
356+ '%s\n '
357+ 'Contents of file %s:\n '
358+ '\n '
359+ '%s' ) % (
360+ ' ' .join ([interpreter , fn ]),
361+ 'env=%s' % self .env ,
362+ fn ,
363+ '----\n %s\n ----' % f .read (),
364+ )
355365 raise VerboseCalledProcessError (msg , e .returncode , e .cmd , output = e .output )
356366 return output
357367
0 commit comments