pytest运行报错:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaf in position 82: illegal multibyte
pytest运行报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xaf in position 82: illegal multibyte sequence
D:\Python\environment\python3.9.7\python3.exe D:/Python/nas_autotest/run.py Traceback (most recent call last): File "D:\Python\nas_autotest\run.py", line 15, in <module> pytest.main(["--junitxml=reports/results.xml"]) # 用例生成执行统计结果 File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 143, in main config = _prepareconfig(args, plugins) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 318, in _prepareconfig config = pluginmanager.hook.pytest_cmdline_parse( File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_hooks.py", line 265, in __call__ return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult) File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_callers.py", line 55, in _multicall gen.send(outcome) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\helpconfig.py", line 100, in pytest_cmdline_parse config: Config = outcome.get_result() File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_result.py", line 60, in get_result raise ex[1].with_traceback(ex[2]) File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_callers.py", line 39, in _multicall res = hook_impl.function(*args) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1003, in pytest_cmdline_parse self.parse(args) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1283, in parse self._preparse(args, addopts=addopts) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1157, in _preparse self._initini(args) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1076, in _initini rootpath, inipath, inicfg = determine_setup( File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 184, in determine_setup rootdir, inipath, inicfg = locate_config([ancestor]) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 106, in locate_config ini_config = load_config_dict_from_file(p) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 45, in load_config_dict_from_file iniconfig = _parse_ini_config(filepath) File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 30, in _parse_ini_config return iniconfig.IniConfig(str(path)) File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 54, in __init__ tokens = self._parse(iter(f)) File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 82, in _parse for lineno, line in enumerate(line_iter): UnicodeDecodeError: 'gbk' codec can't decode byte 0x8d in position 590: illegal multibyte sequence Process finished with exit code 1
解决方式:
第一种:
将pytest.ini文件中的中文字符串去掉
如果需要保留中文备注,则使用第二种方法:
点击报错内容倒数第二个
File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 54, in __init__ tokens = self._parse(iter(f))
这个文件 在52行吧当前的文件打开方式添加上 'utf-8'的解码方式
f = open(self.path,encoding='utf-8')
声明 欢迎转载,但请保留文章原始出处:) 博客园:https://www.cnblogs.com/chenxiaomeng/
如出现转载未声明 将追究法律责任~谢谢合作
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-06-03 使用Postman工具做接口测试(五)——生成随机参数
2021-06-03 使用Postman工具做接口测试(四)——参数化、执行用例与生成测试报告(完结篇)
2021-06-03 使用Postman工具做接口测试(三)——断言与参数提取
2021-06-03 使用Postman工具做基本测试(二)环境变量和请求参数格式
2021-06-03 使用Postman工具做接口测试(一)安装基本功能介绍和简单使用
2021-06-03 <unittest>
2021-06-03 $(document).on和$('#idname').on和$(function(){ })区别