#coding:utf-8
import unittest
from Demo import RunMain
import json
import HTMLTestRunner
class TestMethod(unittest.TestCase):
def setUp(self):
self.run=RunMain()
def test_01(self):
url = ‘http://coding.imooc.com/api/cate’
data = {
'timestamp': '1507006626132',
'uid': '5249191',
'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
'secret': '078474b41dd37ddd5efeb04aa591ec12',
'token': '0b4c502ba647664be04dfedb32ad4f3d',
'cid': '0'
}
res=self.run.run_main(url,'POST',data)
self.assertEqual(res['errorCode'],1007,'测试失败')
print('这是第一个case')
#@unittest.skip('test_02')
def test_02(self):
url = 'http://coding.imooc.com/api/cate'
data = {
'timestamp': '1507006626132',
'uid': '5249191',
'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
'secret': '078474b41dd37ddd5efeb04aa591ec12',
'token': '0b4c502ba647664be04dfedb32ad4f3d',
'cid': '0'
}
res=self.run.run_main(url,'POST',data)
self.assertEqual(res['errorCode'], 1007, '测试失败')
print('这是第二个case')
if name==‘main’:
suite = unittest.TestSuite()
suite.addTest(TestMethod(‘test_01’))
suite.addTest(TestMethod(‘test_02’))
filepath="D:\programs\report\htmlreport.html"
fp=open(filepath,‘wb’)
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=‘this is first report’,description=‘Report_description’)
runner.run(suite)
fp.close()
运行上段代码报错
…Traceback (most recent call last):
File “D:/programs/ImoocInterface/base/test_method.py”, line 51, in
runner.run(suite)
File “D:\programs\lib\HTMLTestRunner.py”, line 629, in run
self.generateReport(test, result)
File “D:\programs\lib\HTMLTestRunner.py”, line 676, in generateReport
report = self._generate_report(result)
File “D:\programs\lib\HTMLTestRunner.py”, line 727, in _generate_report
description = cls_results[0][1].case_name
AttributeError: ‘TestMethod’ object has no attribute ‘case_name’
这个case_name应该在哪里添加?