Call Htmltestrunner Production report content is empty solution

Source: Internet
Author: User

The start code is as follows, and the resulting report content is empty:

#coding =utf-8

Import Unittest,time,re
Import requests
Import JSON
Import Htmltestrunner

Class Test_api (UnitTest. TestCase):

def setUp (self):
Self.url = "Http://10.10.10.92:5050/api/demo/add.do"
SELF.PARAMS1 = {' id ': ' 10011 '}
Self.headers = {' Content-type ': ' Application/json '}
Self.verificationerrors = []
Self.accept_next_alert = True

def test_aad_api (self):
req = Requests.post (Self.url,data=json.dumps (SELF.PARAMS1), headers=self.headers)
Status = Req.status_code
Print (Req.json ())
If status = = 200:
Print ("Add API Interface succeeded")
Else
Print ("Add API interface failed!") ")

def tearDown (self):
Self.assertequal ([], self.verificationerrors)

if __name__ = = "__main__":
Unittest.main ()
#取前面时间
now = Time.strftime ("%y-%m-%d-%h_%m_%s", Time.localtime (Time.time ()))
filename = ' d:\\python-function\\api\\report\\ ' +now+ ' result.html '
fp = open (filename, ' WB ')
#定义测试报告
Runner =htmltestrunner.htmltestrunner (
STREAM=FP,
Title=u ' API test Report ',
Description=u ' use case execution: ')
#执行测试用例
Testsuite = UnitTest. TestSuite ()
#添加测试用例到测试集中
Testsuite.addtest (Test_api ("Test_aad_api"))
Runner.run (Testsuite)

Best of all, think for a long time, and finally found that each report file generated can not be deleted, and then add a,fp.close (), in the implementation, the report has content, hope to be able to help people like me, the complete code is as follows:

#coding =utf-8

Import Unittest,time,re
Import requests
Import JSON
Import Htmltestrunner

Class Test_api (UnitTest. TestCase):

def setUp (self):
Self.url = "Http://10.10.10.92:5050/api/demo/add.do"
SELF.PARAMS1 = {' id ': ' 10011 '}
Self.headers = {' Content-type ': ' Application/json '}
Self.verificationerrors = []
Self.accept_next_alert = True

def test_aad_api (self):
req = Requests.post (Self.url,data=json.dumps (SELF.PARAMS1), headers=self.headers)
Status = Req.status_code
Print (Req.json ())
If status = = 200:
Print ("Add API Interface succeeded")
Else
Print ("Add API interface failed!") ")

def tearDown (self):
Self.assertequal ([], self.verificationerrors)

if __name__ = = "__main__":
Unittest.main ()
#取前面时间
now = Time.strftime ("%y-%m-%d-%h_%m_%s", Time.localtime (Time.time ()))
filename = ' d:\\python-function\\api\\report\\ ' +now+ ' result.html '
fp = open (filename, ' WB ')
#定义测试报告
Runner =htmltestrunner.htmltestrunner (
STREAM=FP,
Title=u ' API test Report ',
Description=u ' use case execution: ')
#执行测试用例
Testsuite = UnitTest. TestSuite ()
#添加测试用例到测试集中
Testsuite.addtest (Test_api ("Test_aad_api"))
Runner.run (Testsuite)
Fp.close ()

So the report will have a content.

Call Htmltestrunner Production report content is empty solution

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.