Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pytest==8.1.1 Import regression in some namespace package layouts #12112

Closed
Assignees
nicoddemus
Labels
@aaraney

Description

@aaraney

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp