• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Mac系统-Pytest-html-文乱码selenium+Pytest

武飞扬头像
子鞍
帮助1

Mac系统-Pytest-html-中文乱码(selenium Pytest)

在自动化测试中,使用Pytest模块生成测试报告时,中文显示乱码该如何解决?


问题描述

在自动化测试中,使用Pytest生成html报告时,打开html文件后,中文显示乱码
学新通

# 原因分析:
>  class TestResult:
      def __init__(self, outcome, report, logfile, config):
          self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")
这里的代码最后已经将编码格式设置为了UTF-8,后面又跟了一个decode("unicode_escape")进行了二次解码
# 解决方案:
#在系统李找到名叫:plugin.py的文件进行更改
#1、进入终端,查看下当前python的路径
which Python3

#2、拿到路径如下:
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3

#3、这时我们只要这一段,复制这段路径,去访达按键盘 commmand shift G
/Library/Frameworks/Python.framework/Versions/3.10

#4、进入后在进入到:/lib/python3.10/site-packages/pytest_html/
lib/python3.10/site-packages/pytest_html/plugin.py

#4.1绝对路径(根据自己的python版本自行更改)
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_html/plugin.py

#5、更改plugin.py(大概在162行,可使用VScode进行编辑)

#更改前:

class TestResult:
      def __init__(self, outcome, report, logfile, config):
          self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")

#更改后:建议把self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")注释掉不要删掉,避免引起其他错误

#class TestResult:
      def __init__(self, outcome, report, logfile, config):
          # 子鞍修改方法,解决乱码问题
           #self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")
          self.test_id = report.nodeid
          
#再次运行你的自动化代码看看,就可以发现中文乱码问题已经解决了。
学新通

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggbgag
系列文章
更多 icon
同类精品
更多 icon
继续加载