Discover (start_dir,pattern= ' test*.py ', Top_level_dir=none)
Find all the test modules under the specified directory, and recursively check the test blocks under subdirectories, only the matching filenames will be loaded. If you are not starting a top-level directory, the top-level directory must be specified separately.
- Start_dir: The directory of the module name or test case to be tested.
- Pattent= ' test*.py ': represents the matching principle for use case filenames. This matches all the. PY type files that begin with the file name a test, * denotes any number of characters.
- Top_level_dir=none: The top-level directory of the test module, if there is no top-level directory, the default is None.
Import UnitTest
Import JSON
Import requests
From Htmltestrunner import Htmltestrunner
Import time
#定义测试用例的目录为当前目录
Test_dir = './testcase '
Discover = unittest.defaultTestLoader.discover (Test_dir,pattern = ' test*.py ')
If __name__== "__main__":
#按照一定的格式获取当前的时间
now = Time.strftime ("%y-%m-%d%h-%m-%s")
#定义报告存放路径
filename = './report ' + now + ' test_result.html '
fp = open (filename, "WB")
#定义测试报告
Runner = Htmltestrunner (stream = FP,
title = "XXX Interface Test Report",
Description = "Test Case execution:")
#运行测试
Runner.run (Discover)
Fp.close () #关闭报告文件
Python Discover function Introduction