91

If I try to execute tests using pytest with python 3.10 I got the following error:

TypeError: required field "lineno" missing from alias

Google says it's a known problem, but I found no way to solve it.
Tests start fine if I launch them with 3.9

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
chydik
  • 1,037
  • 1
  • 7
  • 5

3 Answers3

90

This issue seems to be fixed in pytest version 6.2.5.

Please see: Fix assertion rewriting on Python 3.10

tutuDajuju
  • 10,307
  • 6
  • 65
  • 88
Lewi Uberg
  • 1,055
  • 7
  • 14
33

Just upgrade the pytest PyPI package:

pip install -U pytest
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
  • I still have same problem, is this normal output after this call? - $ pip install -U pytest Defaulting to user installation because normal site-packages is not writeable, others are that Requirement is already satisfied – John May 18 '22 at 17:27
  • 2
    @John I guess your problem is related to the `pip` itself. Try to update the `pip` via `python -m pip install -U pip` or install the `pytest` through `python -m pip install -U pytest` – Benyamin Jafari May 18 '22 at 21:10
  • 2
    I think this is the correct answer (that the solution is to update pytest) but the command to run can be improved. Since we're using poetry to manage our project's dependencies, including its dev dependencies, we should run `poetry remove --dev pytest && poetry add --dev pytest`, which will remove whichever version of pytest was added to the project when it was created and then add the latest version. For me, that meant going from `5.4.3` to `7.1.2`. This process also removed the old transitive dependencies of pytest and then added the new transitive dependencies for the new version. – Matt Welke Jun 18 '22 at 04:58
  • When I did the above steps, and then ran `poetry run pytest`, it worked for me. Since this was a brand new project with no source code yet, and just the initial, automatically-created test, my output said: `1 passed in 0.01s` – Matt Welke Jun 18 '22 at 04:59
0

Meanwhile...I was getting this error during

python3 setup.py pytest

in a library. When I did the following:

pytest -q tests/test_mypackage.py

The error lost, and I got the tests running.

tolga
  • 2,462
  • 4
  • 31
  • 57