# all_tests_pro.py
import unittest,time,os,multiprocessing
import HTMLTestRunner #查找多有含有thread的文件,文件夹
def EEEcreatsuit():
casedir = []
listaa = os.listdir(r'C:\Users\wangxue1\PycharmProjects\selenium2TestOne')
for xx in listaa:
if 'thread' in listaa:
casedir.append(xx)
suite = []
for n in casedir:
testunit = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(n,pattern='test*.py',top_level_dir=n)
print(discover)
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
suite.append(testunit)
print('================casedir:==========',casedir)
print('+++++++++++++++++++++++++++++++++++')
print('!!!!!suite:!!!!!',suite)
return suite,casedir #多进程运行测试套件,将结果写入HTMLTestRunner报告
def EEEEmultiRunCase(suite,casedir):
now = time.strftime('%Y-%m-%d-%H_%M_%S',time.localtime(time.time()))
testreport = 'C:\\Users\\wangxue1\\PycharmProjects\\selenium2TestOne\\' + now + '\\'
filename = testreport + 'report.html'
if not os.path.exists(testreport):
os.makedirs(testreport)
else:
pass
proclist = []
s = 0
with open(filename,'wb') as report:
for i in suite:
runner = HTMLTestRunner.HTMLTestRunner(stream=report,title=u'测试报告',description=u'用例执行情况:')
proc = multiprocessing.Process(target=runner.run(i),args=(i,))
proclist.append(proc)
s = s + 1
for proc in proclist: proc.start()
for proc in proclist: proc.join() runtmp = EEEcreatsuit()
EEEEmultiRunCase(runtmp[0],runtmp[1])