Repository navigation
KeyError fired from importlib during collection when running with --import-mode=importlib on a directory containing a same-named one #12592
Description
Activity
- addedtopic: collectionrelated to the collection phaserelated to the collection phase
on Jul 21, 2024 Feels like this might be an upstream issue; we should try to get a reproducer using stdlib code only.
- added 4 commits that reference this issue
on Aug 30, 2024 - added a commit that references this issue
on Sep 26, 2024 - added a commit that references this issue
on Sep 26, 2024 - added a commit that references this issue
on Sep 26, 2024 cheers for fixing this, folks! I noticed a side-effect of this though: if pytest is running a test on a module that imports e.g.
from cow.moo.farm import udderand there is an
/cow/moo/moo.py, so modulemoo.pyis in a dir identically calledmooand there is no__init__.pyin/moothen the test fails with anImportError- not a biggie since IMHO since one uses package-level imports, then there must be init files all over the place where modules live, it's all good, but just wanted to let you know if yous get some others complaining about it 🍺Seeing a similar issue as #12592 (comment)
Perhaps it's my misunderstanding of namespace packages, but I typically don't have any
__init__.pyfiles in my repo. And I'm seeing anAttributeErrorfor my module now:AttributeError: module 'third_party.my_protobuf_utils.my_protobuf_utils' has no attribute '_read_varint'- added a commit that references this issue
on Dec 4, 2024 Hi, @valeriupredoi @michael-christen
Sorry for seeing these messages so late. Can you please provide a simple reproducible example?
I tried to reproduce an example, Is it the same as this? Please feel free to provide additional examples
- added a commit that references this issue
on Dec 12, 2024 - added a commit that references this issue
on Dec 12, 2024 Hi, @valeriupredoi @michael-christen Sorry for seeing these messages so late. Can you please provide a simple reproducible example?
I tried to reproduce an example, Is it the same as this? Please feel free to provide additional examples
Yep, that's the exact case I have, thanks @dongfangtianyu 🙏
- added a commit that references this issue
on Dec 12, 2024
A detailed description of the bug or problem you are having
When creating the following structure:
then
pytest --import-mode=importlibfails with the following cryptic message:To trigger this bug:
Running with
--pdbgives a slightly more useful backtrace:Output of
pip listfrom the virtual environment you are usingI tried this on a minimal poetry env with just
pytestpytest and operating system versions
pytest 8.2.2. Encountered this both with python 3.10 and python 3.12, so the python version doesn't seem to be a factor.
Running on Ubuntu 22.04.4 LTS.
cc @criemen who encountered this