代码如下,很简单:

import pytest

def test_001():
    print("test_01")

def test_002():
    print("test_02")

if __name__ == "__main__":
    pytest.main("-v","test_1208.py")

报错如下,试了不少方法没能解决

Traceback (most recent call last):
  File "D:\pycharm\PyCharm 2019.2\helpers\pycharm\_jb_pytest_runner.py", line 37, in <module>
    config_result = real_prepare_config(args, plugins_to_load)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "D:\python3\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "D:\python3\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "D:\python3\lib\site-packages\pluggy\_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "D:\python3\lib\site-packages\_pytest\helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "D:\python3\lib\site-packages\pluggy\_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "D:\python3\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1167, in _preparse
    self._consider_importhook(args)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1114, in _consider_importhook
    self._mark_plugins_for_rewrite(hook)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1134, in _mark_plugins_for_rewrite
    for name in _iter_rewritable_modules(package_files):
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 785, in _iter_rewritable_modules
    package_files = list(package_files)
  File "D:\python3\lib\site-packages\_pytest\config\__init__.py", line 1131, in <genexpr>
    for file in dist.files or []
  File "D:\python3\lib\importlib\metadata.py", line 253, in files
    file_lines = self._read_files_distinfo() or self._read_files_egginfo()
  File "D:\python3\lib\importlib\metadata.py", line 268, in _read_files_distinfo
    text = self.read_text('RECORD')
  File "D:\python3\lib\importlib\metadata.py", line 491, in read_text
    return self._path.joinpath(filename).read_text(encoding='utf-8')
  File "D:\python3\lib\pathlib.py", line 1228, in read_text
    return f.read()
  File "D:\python3\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 4: invalid start byte

Process finished with exit code 1

Empty suite

看着像解码问题,但是代码里并没涉及中文。


↙↙↙阅读原文可查看相关链接,并与作者交流