TypeError: attrib() got an unexpected keyword argument 'convert'

PythonPytest

Python Problem Overview


This error occurred during automated testing of a python project on the CI server using pytest. I'm using pytest==4.0.2. This error only just started to occur, previous pipelines seem to work fine.

The full error:

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'

Python Solutions


Solution 1 - Python

pytest seems to have the package attrs as a dependency. attrs==19.2.0 was released around 2019-10-01 17:00 UTC. This seems to cause the problem above.

Switching back to attrs==19.1.0 fixes the problem. Just do the following:

pip install attrs==19.1.0

NOTE: I expect that the issue will be resolved either by attrs or pytest soon by releasing a new version. So this fix should only be temporary.

UPDATE: Moving the comment into the answer. This error does not occur on the newer versions of pytest i.e. pytest==5.2.0

Solution 2 - Python

pytest fixed using deprecated keyword convert at 3.6.3 (https://docs.pytest.org/en/latest/changelog.html#pytest-3-6-3-2018-07-04). At 4.0.1, pytest merged code using convert (https://github.com/pytest-dev/pytest/pull/4427). This code was fixed on 5.2.0 (https://github.com/pytest-dev/pytest/pull/4795).

Solution 3 - Python

pytest version 5.3.1 with attrs Version 19.3.0 works fine for me. [To check the pytest Version and attrs Version issue the following command:]

pip show pytest attrs

I solved the same problem by upgrading pytest module via pip command:

pip install -U pytest

Solution 4 - Python

python -m pip install --upgrade pytest

(anaconda prompt or cmd)

this should solve your problem, as an updated version of pytest automatically takes care of attr issues.

Solution 5 - Python

I have the same error with aws-encryption-cli v2. I have updated my aws-cdk.core lib and it work again with migrate to aws-encryption-cli V2.

pip install -U aws-cdk.core

V2 doc: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/crypto-cli-examples.html#cli-example-encrypt-file

github bug: https://github.com/aws/aws-cdk/issues/3293

Solution 6 - Python

The issue is that with attrs==19.2.0 the convert attribute was removed (source).

attr.ib(convert=int) should be deprecated and replaced by attr.ib(converter=int)

You either need to update whatever is using attrs or you need to downgrade: pip install 'attrs<19.2.0'

Solution 7 - Python

Simply use the command

conda update conda

and restart your system.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnitredView Question on Stackoverflow
Solution 1 - PythonnitredView Answer on Stackoverflow
Solution 2 - PythonAtsushi OdagiriView Answer on Stackoverflow
Solution 3 - Pythoniun1xView Answer on Stackoverflow
Solution 4 - Pythoncode-freezeView Answer on Stackoverflow
Solution 5 - PythonmaxtessView Answer on Stackoverflow
Solution 6 - PythonMartin ThomaView Answer on Stackoverflow
Solution 7 - PythonNikhil ParasharView Answer on Stackoverflow