15
15
"""
16
16
17
17
import argparse
18
+ from collections import deque
18
19
import configparser
19
20
import datetime
20
21
import os
@@ -314,7 +315,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
314
315
max_len_name = len (max (test_list , key = len ))
315
316
316
317
for _ in range (len (test_list )):
317
- test_result , stdout , stderr = job_queue .get_next ()
318
+ test_result , testdir , stdout , stderr = job_queue .get_next ()
318
319
test_results .append (test_result )
319
320
320
321
if test_result .status == "Passed" :
@@ -325,6 +326,14 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
325
326
print ("\n %s%s%s failed, Duration: %s s\n " % (BOLD [1 ], test_result .name , BOLD [0 ], test_result .time ))
326
327
print (BOLD [1 ] + 'stdout:\n ' + BOLD [0 ] + stdout + '\n ' )
327
328
print (BOLD [1 ] + 'stderr:\n ' + BOLD [0 ] + stderr + '\n ' )
329
+ if os .getenv ("PYTHON_DEBUG" , "" ) and os .path .isdir (testdir ):
330
+ # Print the logs on travis, so they are preserved when the vm is disposed
331
+ print ('{}Combine the logs and print the last {} lines ...{}' .format (BOLD [1 ], 4000 , BOLD [0 ]))
332
+ print ('\n ============' )
333
+ print ('{}Combined log for {}:{}' .format (BOLD [1 ], testdir , BOLD [0 ]))
334
+ print ('============\n ' )
335
+ combined_logs , _ = subprocess .Popen ([os .path .join (tests_dir , 'combine_logs.py' ), '-c' , testdir ], universal_newlines = True , stdout = subprocess .PIPE ).communicate ()
336
+ print ("\n " .join (deque (combined_logs .splitlines (), 4000 )))
328
337
329
338
print_results (test_results , max_len_name , (int (time .time () - time0 )))
330
339
@@ -389,13 +398,15 @@ def get_next(self):
389
398
log_stdout = tempfile .SpooledTemporaryFile (max_size = 2 ** 16 )
390
399
log_stderr = tempfile .SpooledTemporaryFile (max_size = 2 ** 16 )
391
400
test_argv = t .split ()
392
- tmpdir = ["--tmpdir=%s/%s_%s" % (self .tmpdir , re .sub (".py$" , "" , test_argv [0 ]), portseed )]
401
+ testdir = "{}/{}_{}" .format (self .tmpdir , re .sub (".py$" , "" , test_argv [0 ]), portseed )
402
+ tmpdir_arg = ["--tmpdir={}" .format (testdir )]
393
403
self .jobs .append ((t ,
394
404
time .time (),
395
- subprocess .Popen ([self .tests_dir + test_argv [0 ]] + test_argv [1 :] + self .flags + portseed_arg + tmpdir ,
405
+ subprocess .Popen ([self .tests_dir + test_argv [0 ]] + test_argv [1 :] + self .flags + portseed_arg + tmpdir_arg ,
396
406
universal_newlines = True ,
397
407
stdout = log_stdout ,
398
408
stderr = log_stderr ),
409
+ testdir ,
399
410
log_stdout ,
400
411
log_stderr ))
401
412
if not self .jobs :
@@ -404,7 +415,7 @@ def get_next(self):
404
415
# Return first proc that finishes
405
416
time .sleep (.5 )
406
417
for j in self .jobs :
407
- (name , time0 , proc , log_out , log_err ) = j
418
+ (name , time0 , proc , testdir , log_out , log_err ) = j
408
419
if os .getenv ('TRAVIS' ) == 'true' and int (time .time () - time0 ) > 20 * 60 :
409
420
# In travis, timeout individual tests after 20 minutes (to stop tests hanging and not
410
421
# providing useful output.
@@ -422,7 +433,7 @@ def get_next(self):
422
433
self .num_running -= 1
423
434
self .jobs .remove (j )
424
435
425
- return TestResult (name , status , int (time .time () - time0 )), stdout , stderr
436
+ return TestResult (name , status , int (time .time () - time0 )), testdir , stdout , stderr
426
437
print ('.' , end = '' , flush = True )
427
438
428
439
class TestResult ():
0 commit comments