TypeError:attrib()获得了意外的关键字参数“转换”

nit*_*red 41 python pytest

在使用CI对CI服务器上的python项目进行自动化测试期间,发生了此错误pytest。我正在使用pytest==4.0.2。这个错误才刚刚开始发生,以前的管道似乎工作正常。

完整错误:

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'
Run Code Online (Sandbox Code Playgroud)

nit*_*red 72

pytest似乎将软件包attrs作为依赖项。attrs==19.2.0被释放了2019-10-01 17:00 UTC。这似乎导致上述问题。

切换回以attrs==19.1.0解决此问题。只需执行以下操作:

pip install attrs==19.1.0
Run Code Online (Sandbox Code Playgroud)

:我希望,这个问题将被解决两种attrspytest很快发布新版本。因此,此修复程序应该只是临时的。

更新:将评论移到答案中。较新版本的pytest不会发生此错误,即pytest==5.2.0

  • 我确认,最好的措施是将pytest更新为最新版本。 (5认同)
  • 我认为版本固定中缺少一个“=”符号。它应该是`pip install --upgrade attrs==19.1.0` (2认同)

iun*_*n1x 8

pytest version 5.3.1 with attrs Version 19.3.0 对我来说很好用。[要检查 pytest 版本和 attrs 版本,请发出以下命令:]

pip show pytest attrs
Run Code Online (Sandbox Code Playgroud)

我通过 pip 命令升级 pytest 模块解决了同样的问题:

pip install -U pytest
Run Code Online (Sandbox Code Playgroud)


小智 7

pytest使用convert3.6.3(https://docs.pytest.org/en/latest/changelog.html#pytest-3-6-3-2018-07-04)中已弃用的关键字修复。在4.0.1版本中,pytest使用converthttps://github.com/pytest-dev/pytest/pull/4427)合并了代码。该代码已在5.2.0(https://github.com/pytest-dev/pytest/pull/4795)上修复。


cod*_*eze 5

python -m pip install --upgrade pytest
Run Code Online (Sandbox Code Playgroud)

(anaconda 提示符或 cmd)

这应该可以解决您的问题,因为 pytest 的更新版本会自动处理 attr 问题。