@@ -326,13 +326,18 @@ def _futurize_test_script(self, filename='mytestscript.py', stages=(1, 2),
326
326
try :
327
327
output = check_output (call_args , stderr = STDOUT , env = self .env )
328
328
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
+ )
336
341
ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError )
337
342
raise ErrorClass (msg , e .returncode , e .cmd , output = e .output )
338
343
return output
@@ -345,13 +350,18 @@ def _run_test_script(self, filename='mytestscript.py',
345
350
output = check_output ([interpreter , fn ],
346
351
env = self .env , stderr = STDOUT )
347
352
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
+ )
355
365
raise VerboseCalledProcessError (msg , e .returncode , e .cmd , output = e .output )
356
366
return output
357
367
0 commit comments