Mac系统-Pytest-html-文乱码selenium+Pytest
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
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13