Python Discover function Introduction

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.