pytest-dev / py

Python development support library (note: maintenance only)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pyimport raises ImportMismatchError

gillesdouaire opened this issue · comments

Here's our case:

We run our build pipelines in Gitlab with Windows runners.

  1. We create a Python virtual env using 'Gitlab runner A'. This will create a Python virtualenv with runner A's path hardcoded 'everywhere'.

  2. We save the virtual environment using Gitlab's artifacts.

  3. We download the virtual env built under 'Gitlab runner A' and in certain cases, we use it under 'Gitlab runner B'. Because a) Python has the habit of using absolute paths in the venvs, and b) Gitlab uses different paths for each runner, to make the venv usable, we created a symlink named after the path for 'Gitlab runner A' and pointing to 'Gitlab runner B'.

  4. Step 3 works in every situation we have encountered in the last year, except with pytest when we started using custom plugins. That context raises ImportMismatchError, even if the venv if fully functional; the check is purely nominal (path A is not equal to path B), whereas both paths work, because we have the symlink and the actual physical path.

COS:

  • raise an error only when the functionality is actually broken ?
  • have the possibility to ignore the error?
  • do not ignore symlinks?

With the recently released 1.7.0, you can set PY_IGNORE_IMPORTMISMATCH=1 to suppress that error when you know it is a false negative.

This has been discussed at length in pytest-dev/pytest#2042, but no workable solution has been found in a long time.

I'm closing now, but feel free to follow up with further questions.