前段時間在網上學習多線程跑用例的時,發現一種更簡潔,優雅的使用多線程的方法,在此分享給大家。
閱讀本文前,請先閱讀前面寫的多線程跑用例的文章:【精選】第七章 第四節 自動化測試高級應用之python多線程的使用_add_test_img-CSDN博客
本文新的方法,對原有的run_allcase.py進行了改寫,分為test_runner.py 和run_allcase.py兩個文件。
test_runner.py源碼如下:
from selenium_lib.common import *
from BeautifulReport import BeautifulReport
import unittest, time, os
from multiprocessing.dummy import Poolclass TestRunner(object):def __init__(self, testor="QA",title="UI自動化測試報告",description="測試用例批量執行"):self.testor = testorself.title = titleself.des = description# 獲取當前時間,并轉化成我們想要的格式self.now_time = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.tim