Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest uses the source of the package instead of the installed version #12594

Open
Czaki opened this issue Jul 10, 2024 · 1 comment
Open

Pytest uses the source of the package instead of the installed version #12594

Czaki opened this issue Jul 10, 2024 · 1 comment
Labels
topic: collection related to the collection phase

Comments

@Czaki
Copy link

Czaki commented Jul 10, 2024

I had meet a problem when running code with pytest 8.2.2 that test are importing modules from source, not from the installed version of package, that leads to test fail, as the package contains modules that need to be downgraded.

   ==================================== ERRORS ====================================
  _________________ ERROR collecting mahotas/tests/test_bbox.py __________________
  ImportError while importing test module '/project/mahotas/tests/test_bbox.py'.
  Hint: make sure your test modules/packages have valid Python names.
  Traceback:
  /project/mahotas/tests/test_bbox.py:4: in <module>
      from mahotas import bbox
  /project/mahotas/bbox.py:8: in <module>
      from . import _bbox
  E   ImportError: cannot import name '_bbox' from 'mahotas' (/project/mahotas/__init__.py)

https://github.com/luispedro/mahotas/actions/runs/9771967420/job/26975569344#step:3:994

However, when downgrade to pytest 8.1.1 it works again:

https://github.com/luispedro/mahotas/actions/runs/9873149918/job/27264790877?pr=149
luispedro/mahotas#149

I have tried locally to switch to src layout, but it does not solve the issue.

From simple test it looks like all 8.2.0, 8.2.1 and 8.2.2 are affected.

pytest is invoked with import-mode=importlib to use code from library, not local version: https://github.com/luispedro/mahotas/blob/5793160940ad88caf3a4113d76f498265d4b3d06/pyproject.toml#L7

maybe you could see an obvious problem with project configuration, but it worked in the past.

@pygeek
Copy link

pygeek commented Jul 11, 2024

Possibly related to:
8.1->8.0

Changes to import resolution logic: #11475
Bug fix related to importlib: #12208

@Zac-HD Zac-HD added the topic: collection related to the collection phase label Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase
Projects
None yet
Development

No branches or pull requests

3 participants