the python unittest unit testing framework - loading test, run the test case generating a test report - load all cases with a folder by discover

Import OS
 Import the unittest
 Import HTMLTestRunnerNew 

# . 1, initialization testloader 
testloader = unittest.TestLoader () 

# 2, to find test, loading 
the dir = os.path.dirname (os.path.abspath with ( __FILE__ )) 
case_dir = the os.path.join (dir, ' test_cases ' ) 

Suite = testloader.discover (case_dir) 


# create a folder to store test report -report 
report_path = os.path.join (dir, ' report ' )
 IF  not os.path.exists (report_path): 
    os.mkdir (report_path) 

file_pathOs.path.join = (report_path, ' test_result.html ' ) 

with Open (file_path, " wb + " ) AS f:
     # initialize the run, is plain text report generation TextTestRunner 
    Runner = HTMLTestRunnerNew.HTMLTestRunner (Stream = f, = title " the API test report ' , Description = ' execution example details use ' , = Tester ' BenBen ' )
     # run test 
    runner.run (suite)

Guess you like

Origin www.cnblogs.com/benben-wu/p/12131564.html