【Python】pytest - 运行错误

Posted by 西维蜀黍 on 2019-11-18, Last Modified on 2021-09-21

Problem

当执行 py.test时,报错:

File "/usr/local/lib/python3.7/site-packages/_pytest/tmpdir.py", line 35, in TempPathFactory
    lambda p: Path(os.path.abspath(six.text_type(p)))
TypeError: attrib() got an unexpected keyword argument 'convert'

Solution

查看 py.test 版本:

$  py.test --version     
This is pytest version 4.0.2, imported from /Working/backend/venv/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-mock-1.11.2 at /Working/backend/venv/lib/python2.7/site-packages/pytest_mock/__init__.pyc
  pytest-cov-2.8.1 at /Working/backend/venv/lib/python2.7/site-packages/pytest_cov/plugin.py

pip list 查看当前安装的 attrs 版本,pytest 依赖于 attrs

attrs==19.2.0引入了上面的错误,因此将 attrs 切回到 19.1.0版本:

$ pip install attrs==19.1.0

Reference