笃行之.kiss
2021-04-15 14:43
采纳率: 58.8%
浏览 169

pytest 配置pytest.ini文件之后运行报错

[pytest]

#命令行参数
addopts = -vs

#搜索目录
testpaths = ./

#测试用例收集规则
python_files = *_test.py
python_classes = Test*
python_functions = test_*

E:\github\python\python_module\pytest_module>pytest
Traceback (most recent call last):
  File "e:\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "E:\Programs\Python\Python38\Scripts\pytest.exe\__main__.py", line 7, in <module>
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 1157, in _preparse
    self._initini(args)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 1076, in _initini
    rootpath, inipath, inicfg = determine_setup(
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\findpaths.py", line 184, in determine_setup
    rootdir, inipath, inicfg = locate_config([ancestor])
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\findpaths.py", line 106, in locate_config
    ini_config = load_config_dict_from_file(p)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\findpaths.py", line 45, in load_config_dict_from_file
    iniconfig = _parse_ini_config(filepath)
  File "C:\Users\057776\AppData\Roaming\Python\Python38\site-packages\_pytest\config\findpaths.py", line 30, in _parse_ini_config
    return iniconfig.IniConfig(str(path))
  File "e:\programs\python\python38\lib\site-packages\iniconfig\__init__.py", line 54, in __init__
    tokens = self._parse(iter(f))
  File "e:\programs\python\python38\lib\site-packages\iniconfig\__init__.py", line 82, in _parse
    for lineno, line in enumerate(line_iter):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 27: illegal multibyte sequence

E:\github\python\python_module\pytest_module>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • 张岂逢 2021-04-15 22:15
    已采纳
    import configparser
    
    config.read("configFile.ini",encoding="utf8")
    点赞 打赏 评论
  • 芫尘梦 2021-04-15 15:11

    用的是gbk 改成utf-8试试

    点赞 打赏 评论
  • mee-ovo 2021-07-21 17:16

    把file codeing改成“GBK”试一下 ,我的可以正常运行了。

    点赞 打赏 评论
  • 外卖仔何金银 2021-09-07 17:34

    找到python环境下的iniconfig_init.py
    比如我的pyhton路径是:F:\python3.8.6\Lib\site-packages\iniconfig_init
    .py,增加红框内容

    img

    点赞 打赏 评论

相关推荐 更多相似问题