import os
import unittest
import HTMLTestRunner
''''该模块用来执行当前目录下,所有以test开头的py文件'''
def allTests():
suite=unittest.TestLoader().discover(start_dir=os.path.dirname(__file__),pattern='test*.py', top_level_dir=None)
return suite
# ----不生成报告,只运行Testcase目录下,已test开头的文件
# def run():
# unittest.TextTestRunner(verbosity=2).run(allTests())
# ----生成报告,并且将报告放在report这个文件夹下
def run():
'''拼接目录'''
fp=os.path.join(os.path.dirname(__file__),'report','testreport.html')
'''wb:w表示写,b表示字节。一定要用wb'''
HTMLTestRunner.HTMLTestRunner(stream=open(fp,'wb'),title='搜索和商品详情页测试报告',description='搜索和商品详情页自动化测试报告').run(allTests())
if __name__ == '__main__':
run()
![]()
![]()