Generating a test report file in HTML format using the Htmltestrunner module

Source: Internet
Author: User

1. Download htmltestrunner.py

Htmltestrunner is an extension of the UnitTest module of the Python Standard library. It generates easy-to-use HTML test reports. Htmltestrunner is issued under the BSD license.
Download Address: http://tungwaiyip.info/software/HTMLTestRunner.html

Windows: Put the downloaded files into the PYTHON34 installation directory ... \python34\lib directory

2. Import the Htmltestrunner module package

1  fromHtmltestrunnerImportHtmltestrunner2 ImportUnitTest3  fromTimeImportstrftime or import time,datetime4 ImportOS5  fromEmail.mime.textImportMimetext6 7  fromEmail.mime.multipartImportMimemultipart#Message Format8 9  fromEmail.mime.imageImportMimeimage#send a message with picture

3. Defining test Case paths

' ./testcase/ '

Or

' test_case\\testcase '

4. Find Elements (TestCase)

Discover = Unittest.defaultTestLoader.discover (Test_dir,'*case.py')

5. Define the test report file name and take the previous time to add to the test report file name

# define report Storage path, support relative path

' ./report/ ' + strftime ('%y_%m_%d_%h_%m_%s'. html' )

6. Create a file

fp = open (file_name,'wb')
Htmltestrunner (stream=fp,description=' description ', title=' title '). Run (Discover)

7. Close the file

Fp.close ()

Attachment:

#-*-coding:utf-8-*-ImportUnitTest fromHtmltestrunnerImportHtmltestrunnerImportTime,os,datetimeImportSmtplib fromEmail.mime.textImportMimetext fromEmail.mime.multipartImportMimemultipart fromEmail.mime.imageImportMimeimage#fetch all use case files under the Test_case folderdefCreatsuitel (lists): Testunit=UnitTest. TestSuite ()#Discover method DefinitionDiscover = Unittest.defaultTestLoader.discover (lists, pattern='start_*.py', top_level_dir=None)#the Discover method filters out the use cases, loops to add to the test suite     forTest_suiteinchDiscover: forTest_caseinchtest_suite:testunit.addTests (test_case)Print(Testunit)returntestunitlist_1='Test_case\\test_case_1'Alltestnames=Creatsuitel (list_1)#take the previous time to add to the test report file namenow = Time.strftime ("%y-%m-%m-%h_%m_%s", Time.localtime (Time.time ())) filename="report\\"+now+'result.html' #defines a report storage path that supports relative paths. fp = open (filename,'WB') Runner= Htmltestrunner (STREAM=FP, title='Report_title', description='report_description')if __name__=="__main__":    #executing test case sets and generating reportsRunner = UnitTest. Texttestrunner ()




Generating a test report file in HTML format using the Htmltestrunner module

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.