import unittest import os, datetime, time from BeautifulReport import BeautifulReport from framework.excel_oprate import read_config from tomorrow import threads root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/') test_dir = root_dir + '/testcases' report_dir = root_dir + '/test_report' def add_cases(): discover = unittest.defaultTestLoader.discover(test_dir, 'test*.py', None) testsuit01 = unittest.TestSuite() testsuit02 = unittest.TestSuite() table_datas = read_config() for test01 in discover: for test02 in test01: for test03 in test02: testsuit01.addTest(test03) for case in testsuit01: case01 = str(case) case01 = case01.split('(')[0].strip() for i in range(len(table_datas)): case_name = table_datas[i]['测试用例'] if case_name == case01: if table_datas[i]['是否执行'] == float(1.0): testsuit02.addTest(case) print('----->要运行的测试用例:') for te in testsuit02: print(te) return testsuit02 @threads(2) def run(test_suit): now = datetime.datetime.now().strftime('%Y-%m-%d %H_%M_%S') filename = '测试报告' + str(now) result = BeautifulReport(test_suit) result.report(filename=filename, description='测试报告', log_path=report_dir) if __name__ == '__main__': cases = add_cases() for case in cases: run(case)
或者如下:
import unittest
import os, datetime
from BeautifulReport import BeautifulReport
from framework.excel_oprate import read_config
from tomorrow import threads
root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/')
test_dir = root_dir + '/testcases'
report_dir = root_dir + '/test_report'
def add_cases():
discover = unittest.defaultTestLoader.discover(test_dir, 'test*.py', None)
testsuit01 = unittest.TestSuite()
testsuit02 = unittest.TestSuite()
table_datas = read_config()
for test01 in discover:
for test02 in test01:
for test03 in test02:
testsuit01.addTest(test03)
for case in testsuit01:
case01 = str(case)
case01 = case01.split('(')[0].strip()
for i in range(len(table_datas)):
case_name = table_datas[i]['测试用例']
if case_name == case01:
if table_datas[i]['是否执行'] == float(1.0):
testsuit02.addTest(case)
print('----->要运行的测试用例:')
for te in testsuit02:
print(te)
return testsuit02
@threads(5)
def run(test_suit):
filename = '测试报告'
result = BeautifulReport(test_suit)
result.report(filename=filename, description='测试报告',
log_path=report_dir)
if __name__ == '__main__':
now = datetime.datetime.now().strftime('%Y-%m-%d %H_%M_%S')
report_name = '测试报告' + str(now) + '.html'
cases = add_cases()
for case in cases:
result = run(case)
os.chdir(report_dir)
if os.path.exists('测试报告.html'):
os.rename('测试报告.html', report_name)
今天的文章
bat脚本start用法_bat脚本start用法分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/60731.html