2.6 all_test.py总执行文件

all_test.py这个文件是调用test_case下面的所有的.py文件,并且自动执行test_case里面以test开头的用例,执行顺序按照ascii码。

具体是怎么展现的看如下

因为生成测试报告需要借助第三方的模块,所以接下来要配置HTMLTestRunnner.py文件,将该文件放到C:\Program Files\Python35\Lib下面 

先到网盘将HTMLTestRunnner.py下载

链接:https://pan.baidu.com/s/1foTU9UdAZiV1HBpWbgXF-A
提取码:ky0w 

接着将该文件放到C:\ProgramFiles\Python35\Lib下面 

然后创建一个python.File,命名为all_test.py


扫描二维码关注公众号,回复: 4792976 查看本文章

下面为all_test.py的代码

from HTMLTestRunner import HTMLTestRunner
import unittest,time,os
test_case_ = os.path.dirname(os.path.realpath(__file__))
print(test_case_)
test_case = os.path.join(test_case_,"test_case")
print(test_case)
test_report = os.path.join(test_case_,"report")
print(test_report)

test_list = unittest.defaultTestLoader.discover(test_case,pattern="test*.py")

if __name__ == '__main__':
    now = time.strftime("%Y_%m_%d %H_%M_%S")
    filename = test_report + "\\" + now + "_result.html"
    fp = open(filename,'wb')
    runner = HTMLTestRunner(stream=fp,
                            title=u"写你项目名字",
                            description="window10 Chrome browser 62.0 version写你测试的环境")
    runner.run(test_list)
    fp.close()

 这里主编有个小失误,如果想成功运行成下图的展示,需要将test1.py.py文件改一下,改成以test_的模式如下图我改成test_web

猜你喜欢

转载自blog.csdn.net/weixin_42378396/article/details/84875389