• 在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>


    在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>

      print >> sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime) 或print(sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime)) 修改为 sys.stderr.write(' Time Elapsed: %s ' % (self.stopTime - self.startTime))

    如下图这样

    # -*- coding: UTF-8 -*-
    import unittest
    from BSTestRunner import BSTestRunner
    import time
    import smtplib                           #发送邮件模块
    from email.mime.text import MIMEText    #定义邮件内容
    from email.header import Header         #定义邮件标题
    import os
    import sys
    
    path='D:\AUTO\kyb_testProject\'
    sys.path.append(path)
    别忘了指定路径 不然jekins 执行不了


    def send_mail(reports): f=open(reports,'rb') mail_content = f.read() f.close() smtpserver = 'smtp.qq.com' user = '3481073579@qq.com' password = 'ethxyyouqtficiha' sender = '3481073579@qq.com' receives = ['huzy@southgnss.com', ''] subject = 'kyb_自动化测试报告' #content = '<html><h1 style="color:red">我要自学网,自学成才!</h1></html>' msg = MIMEText(mail_content, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = sender msg['To'] = ','.join(receives) smtp = smtplib.SMTP_SSL(smtpserver, 465) smtp.helo(smtpserver) smtp.ehlo(smtpserver) smtp.login(user, password) print("Start send email...") smtp.sendmail(sender, receives, msg.as_string()) smtp.quit() print("Send email end!") def latest_report(report_dir): lists = os.listdir(report_dir) print(lists) lists.sort(key=lambda fn: os.path.getatime(report_dir + '\' + fn)) print("the latest report is " + lists[-1]) file = os.path.join(report_dir, lists[-1]) print(file) return file if __name__ == '__main__': report_dir= '../reports' test_dir = '../test_case' discover = unittest.defaultTestLoader.discover(test_dir, pattern="test_login.py") now=time.strftime("%Y-%m-%d %H_%M_%S") report_name=report_dir+'/'+now+'result.html' with open(report_name,'wb') as f: runner=BSTestRunner(stream=f,title="Test Report",description="kyb Android app test report") runner.run(discover) latest_report=latest_report(report_dir) send_mail(latest_report)
  • 相关阅读:
    vue2.0子组件修改父组件props数据的值
    Visual Studio串口通信与测控应用编程实践
    电梯安装与调试技术
    拾年
    人文生态视野下的城市景观形态研究
    生物真让人惊奇
    神奇生理科学美图大观
    藏在文物里的中国史2 夏商周
    思科UCS服务器统一计算
    Google改变生活
  • 原文地址:https://www.cnblogs.com/zhenyu1/p/12613418.html
Copyright © 2020-2023  润新知