# -*- coding:utf-8 -*-
# !/usr/bin/python3
import _thread
import time,io,sys
import unittest,threading
import HTMLTestRunner_PY3
def load_testcase():
# 定义测试套件
# suite = unittest.TestSuite()
# # 加载测试用例
loader = unittest.TestLoader()
suite = loader.loadTestsFromTestCase(TestTaskNew)
return suite
def run_suite(suite):
# 执行测试用例,并将执行结果保存到文件中
with open("./result.html", mode='wb') as f:
runner = HTMLTestRunner_PY3.HTMLTestRunner(f,verbosity=2,title="我的HTML测试报告")
result = runner.run(suite)
return result
def main():
suite = load_testcase()
try:
for i in range(10):
_thread.start_new_thread(run_suite,(suite,))
print("线程已启动")
time.sleep(10)
except:
print("线程未启动")
def test_task(name):
print(f"{threading.current_thread().name}:",name)
time.sleep(10)
class TestTaskNew(unittest.TestCase):
def test01(self):
test_task(1)
def test02(self):
test_task(2)
def test03(self):
test_task(3)
def test04(self):
test_task(4)
def test05(self):
test_task(5)
def test06(self):
test_task(6)
def test07(self):
test_task(7)
def test08(self):
test_task(8)
def test09(self):
test_task(9)
def test10(self):
test_task(10)
if __name__ == '__main__':
# 使用_thread来实现多线程
main()
目前无论怎么执行还是这样子的: