51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1439|回复: 3

执行测试用例后,报错了,不知道哪里出问题,有大神帮忙看一下不?

[复制链接]
  • TA的每日心情
    无聊
    8 小时前
  • 签到天数: 396 天

    连续签到: 2 天

    [LV.9]测试副司令

    发表于 2020-6-9 10:47:22 | 显示全部楼层 |阅读模式
    执行测试用例后,报错了,不知道哪里出问题,有大神帮忙看一下不?

    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
    复制代码


    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-3-11 10:55
  • 签到天数: 643 天

    连续签到: 1 天

    [LV.9]测试副司令

    发表于 2020-6-10 09:29:15 | 显示全部楼层
    ui自动化把这是
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    9 小时前
  • 签到天数: 1659 天

    连续签到: 2 天

    [LV.Master]测试大本营

    发表于 2020-6-10 10:57:13 | 显示全部楼层
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    11 小时前
  • 签到天数: 2651 天

    连续签到: 3 天

    [LV.Master]测试大本营

    发表于 2020-6-10 12:19:55 | 显示全部楼层
    报错类型不对
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-16 18:33 , Processed in 0.071532 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表