pytest-dev / pytest-dev/pytest
Pytest uses the source of the package instead of the installed version
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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
https://github.com/luispedro/mahotas/pull/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the import-mode=importlib setting in pyproject.toml and reproduce the failure using mahotas/tests/test_bbox.py. Compare behavior between pytest 8.1.1 and 8.2.x using the linked CI runs and configuration. Done means identifying why installed-package imports changed and defining a regression-safe fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100