Outdated Pytest Version in Poetry

Problem

Recently, I have updated my operating system, and as a part of this process I have installed the latest poetry version (a tool for Python dependency management). When I have started a new project using my typical routine, I have discovered that poetry cannot install development dependencies exiting with a weird SolverProblemError error.

I have managed to find the cause of this issue. Exploring the problem (at first, I blamed WPS package for this issue, then pytest-xdist), I have managed to find a minimum working example to reproduce it.

Let me show it. Try to create a new project with poetry:

$ poetry new --src poetry_proj
Created package poetry_proj in poetry_proj
$ cd poetry_proj
$ poetry add --dev pytest-xdist
Creating virtualenv poetry-proj in /home/yury/tmp/poetry_proj/.venv
Using version ^2.1.0 for pytest-xdist

Updating dependencies
Resolving dependencies... (0.1s)

[SolverProblemError]
Because no versions of pytest-xdist match >2.1.0,<3.0.0
 and pytest-xdist (2.1.0) depends on pytest (>=6.0.0), pytest-xdist (>=2.1.0,<3.0.0) requires pytest (>=6.0.0).
So, because poetry-proj depends on both pytest (^5.2) and pytest-xdist (^2.1.0), version solving failed.

As you can see, adding just one dependency (pytest-xdist) results in the SolverProblemError error. Unfortunately, the error string does not explain well what causes the error.

Solution

Apparently, the root of the issue is in an outdated pytest dependency. When you create a Python project using poetry, by default it adds to the list of development packages the pytest dependency. If you open pyproject.toml file just after creating a project, you will find these lines:

...
[tool.poetry.dev-dependencies]
pytest = "^5.2"
...

Such specification of the pytest dependency means that the project requires pytest version >=5.2 and <6.0. However, recently updated pytest-xdist requires pytest version >=6.0.0. Poetry cannot resolve this dependency version conflict and raises the error.

When I found the root of the issue, the solution became obvious. After creating a Python project with poetry, open pyproject.toml and substitute pytest = "^5.2" with, e.g., pytest = "^6.0":

...
[tool.poetry.dev-dependencies]
pytest = "^6.0"
...

Now, if you try to add pytest-xdist it will be installed without errors:

$ poetry add --dev pytest-xdist
Using version ^2.1.0 for pytest-xdist

Updating dependencies
Resolving dependencies... (1.0s)

Writing lock file


Package operations: 14 installs, 0 updates, 0 removals

  - Installing pyparsing (2.4.7)
  - Installing six (1.15.0)
  - Installing attrs (20.1.0)
  - Installing iniconfig (1.0.1)
  - Installing more-itertools (8.5.0)
  - Installing packaging (20.4)
  - Installing pluggy (0.13.1)
  - Installing py (1.9.0)
  - Installing toml (0.10.1)
  - Installing apipkg (1.5)
  - Installing pytest (6.0.1)
  - Installing execnet (1.7.1)
  - Installing pytest-forked (1.3.0)
  - Installing pytest-xdist (2.1.0)

Currently, I do not see any issues with this fix. Therefore, I recommend to use it if you face with the same error.

Related