51Testing软件测试论坛

标题: 执行测试用例后,报错了,不知道哪里出问题,有大神帮忙看一下不? [打印本页]

作者: 测试积点老人    时间: 2020-6-9 10:47
标题: 执行测试用例后,报错了,不知道哪里出问题,有大神帮忙看一下不?
执行测试用例后,报错了,不知道哪里出问题,有大神帮忙看一下不?

  1. import requests
  2. import unittest
  3. import os
  4. import time
  5. import sys
  6. from HTMLTestRunner import HTMLTestRunner


  7. class AddFile(unittest.TestCase):

  8.     def addFile(self, pid, cname):
  9.         url = 'https://webapi.115.com/files/add'
  10.         header = {
  11.             'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 115Browser/13.0.0'}
  12.         cookie = {
  13.             'Cookie': 'acw_tc=784e2ca715906270849083403e4526dea21825ed693b2174d77b4f052244d4; UID=593103455_A1_1590628294; CID=a372b3a2a4835637db65773b5d003817; SEID=f9308c546fe8c23268964cd7f3ff4bf020abb4ef7f7419b3c4b662761e7279ac041058ad29e78ebe719f0bc1600c16c564e6eb6df5bce9f93dd996b9'
  14.         }
  15.         param = {'pid': pid, 'cname': cname}

  16.         resp = requests.post(url=url, headers=header, cookies=cookie, data=param)
  17.         result = resp.json()
  18.         # print(result)
  19.         if result['state'] is True:
  20.             self.assertIs(result['state'], True)
  21.             print(result['state'], '添加文件夹成功!')
  22.         else:
  23.             self.assertIs(result['state'], False)
  24.             print(result['error'])

  25.     # 测试添加的文件夹名称已存在,添加失败
  26.     def test_addFile1(self):
  27.         self.addFile(0, '魂牵梦萦')

  28.     # 测试添加的文件夹名称不存在,可以正常添加
  29.     def test_addFile2(self):
  30.         self.addFile(0, '通过接口自动化添加的文件夹')


  31. if __name__ == '__main__':
  32.     # 构造测试集
  33.     suite = unittest.TestSuite()
  34.     # 添加测试用例
  35.     suite.addTest(AddFile('test_addFile1'))
  36.     suite.addTest(AddFile('test_addFile2'))

  37.     # 获取当前执行时间
  38.     # date = time.strftime('%Y-%m-%d')
  39.     time = time.strftime('%Y-%m-%d %H-%M-%S')
  40.     # 执行测试
  41.     path = './report/'
  42.     # 判断定义的测试报告保存路径是否存在,不存在则创建
  43.     if not os.path.exists(path):
  44.         os.makedirs(path)
  45.     else:
  46.         pass
  47.     # 定义文件保存名字
  48.     filename = path + time + '_report.html'

  49.     report_title = u'测试报告'
  50.     desc = u'接口自动化测试报告详情:'

  51.     with open(filename, 'wb') as report:
  52.         runner = HTMLTestRunner.HTMLTestRunner(stream=report, title=report_title, description=desc)
  53.         runner.run(suite)

  54.     # 关闭report
  55.     report.close()
  56.     # unittest.main()

复制代码
运行后报错:

  1. "D:\Program Files\Python\Python37\python.exe" E:/study/python/115Interface/addFile.py
  2. ..Traceback (most recent call last):
  3.   File "E:/study/python/115Interface/addFile.py", line 64, in <module>
  4.     runner.run(suite)
  5.   File "D:\Program Files\Python\Python37\lib\site-packages\HTMLTestRunner\HTMLTestRunner.py", line 631, in run
  6.     self.generateReport(test, result)
  7.   File "D:\Program Files\Python\Python37\lib\site-packages\HTMLTestRunner\HTMLTestRunner.py", line 691, in generateReport
  8.     self.stream.write(output)
  9. TypeError: a bytes-like object is required, not 'str'

  10. Process finished with exit code 1
复制代码



作者: bellas    时间: 2020-6-10 09:29
ui自动化把这是
作者: 海海豚    时间: 2020-6-10 10:57
https://www.fujieace.com/python/str-bytes.html 参考下
作者: jingzizx    时间: 2020-6-10 12:19
报错类型不对




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2