Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
As first noted in#12074, below is an example project structure with two packages under thens
namespace that now fail to import after the changes introduced in8.1.x
:
ns└── python ├── bar │ ├── ns │ │ ├── bar │ │ └── test │ │ ├── __init__.py │ │ ├── bar.py │ │ └── test_bar.py │ └── pyproject.toml └── foo ├── ns │ ├── foo │ └── test │ ├── __init__.py │ ├── foo.py │ └── test_foo.py └── pyproject.toml
Below are the contents oftest_foo.py
andfoo.py
.test_bar.py
andbar.py
look nearly identical.
# python/foo/ns/test/test_foo.pyfrom .foo import valuedef test_foo(): assert value == "foo"
# python/foo/ns/test/foo.pyvalue = "foo"
Inpytest==8.0.2
,python -m pytest --import-mode=importlib
correctly discovers and runs the tests from the top levelns
directory. Inpytest==8.1.1
,python -m pytest --import-mode=importlib -o "consider_namespace_packages=true"
, results in the following error during collection:
========================== test session starts ===========================platform darwin -- Python 3.9.16, pytest-8.1.1, pluggy-1.4.0rootdir: /home/user/pytest-12074collected 0 items / 2 errors================================= ERRORS =================================____________ ERROR collecting python/bar/ns/test/test_bar.py _____________ImportError while importing test module '/home/user/pytest-12074/python/bar/ns/test/test_bar.py'.Hint: make sure your test modules/packages have valid Python names.Traceback:python/bar/ns/test/test_bar.py:1: in <module> from .bar import valueE ModuleNotFoundError: No module named 'test.bar'____________ ERROR collecting python/foo/ns/test/test_foo.py _____________ImportError while importing test module '/home/user/pytest-12074/python/foo/ns/test/test_foo.py'.Hint: make sure your test modules/packages have valid Python names.Traceback:python/foo/ns/test/test_foo.py:1: in <module> from .foo import valueE ModuleNotFoundError: No module named 'test.foo'======================== short test summary info =========================ERROR python/bar/ns/test/test_bar.pyERROR python/foo/ns/test/test_foo.py!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!=========================== 2 errors in 0.04s ============================
To reproduce the issue clonehttps://github.com/aaraney/pytest-12074, pip installns.foo
andns.bar
, pip install the different versions ofpytest
and run with the aforementioned commands.