-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix: Resolved an ImportError
crash when using --import-mode=importlib
#13053
Conversation
c5a7ed8
to
ddb0306
Compare
Thanks @valeriupredoi @michael-christen for feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dongfangtianyu, appreciate the PR!
many thanks @dongfangtianyu - I'm sure it does, I took a look at the code, and if @nicoddemus approved then I think it's all spiffy 🍺 |
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #13054 🤖 @patchback |
Regression in #12716 In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead. **Trigger conditions:** 1. `/cow/moo/moo.py` exists (a file and directory with the same name). 2. `/cow/moo/test_moo.py` exists (test case resides in the directory). When pytest loads test files in `importlib` mode, it continues recursive loading upward: - When loading `cow.moo`, it should return a namespace but unexpectedly returns a module. - When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace. **Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue) - `main.py`: Reproduces the error. - `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`. **Context:** #12592 (comment) #12592 (comment) --------- Co-authored-by: Bruno Oliveira <[email protected]> (cherry picked from commit 28e1e25)
…#13054) Regression in #12716 In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead. **Trigger conditions:** 1. `/cow/moo/moo.py` exists (a file and directory with the same name). 2. `/cow/moo/test_moo.py` exists (test case resides in the directory). When pytest loads test files in `importlib` mode, it continues recursive loading upward: - When loading `cow.moo`, it should return a namespace but unexpectedly returns a module. - When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace. **Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue) - `main.py`: Reproduces the error. - `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`. **Context:** #12592 (comment) #12592 (comment) --------- Co-authored-by: Bruno Oliveira <[email protected]> (cherry picked from commit 28e1e25) Co-authored-by: dongfangtianyu <[email protected]>
Can confirm, this fixed the issue I was experiencing, thanks again, you're the best @dongfangtianyu! |
Regression in #12716
In short:
PathFinder.find_spec
received the argument/cow/moo
but loaded/cow/moo/moo.py
instead.Trigger conditions:
/cow/moo/moo.py
exists (a file and directory with the same name)./cow/moo/test_moo.py
exists (test case resides in the directory).When pytest loads test files in
importlib
mode, it continues recursive loading upward:cow.moo
, it should return a namespace but unexpectedly returns a module.cow.moo.moo
, it should return a module but unexpectedly returns a namespace.Complete example: [GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)
main.py
: Reproduces the error.debug.py
: Demonstrates the behavior ofPathFinder.find_spec
.Context:
#12592 (comment)
#12592 (comment)