前段时间在网上学习多线程跑用例的时,发现一种更简洁,优雅的使用多线程的方法,在此分享给大家。
阅读本文前,请先阅读前面写的多线程跑用例的文章:【精选】第七章 第四节 自动化测试高级应用之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