Wrong relative imports in unit tests with parallel hierarchy
See original GitHub issueI’m having a problem similar to https://github.com/davidhalter/jedi-vim/issues/195, here is a step by step procedure to reproduce the issue:
mkdir /tmp/proj
cd /tmp/proj
mkdir pkg
touch pkg/__init__.py
touch pkg/mod.py
mkdir tests
touch tests/__init__.py
mkdir tests/pkg
touch tests/pkg/__init__.py
touch tests/pkg/test_mod.py
export PYTHONPATH=/tmp/proj:$PYTHONPATH
vim tests/pkg/test_mod.py
Now try to autocomplete import pkg.
, jedi will suggest only test_mod
, which is wrong given the PYTHONPATH
, and won’t suggest mod
, which is also wrong.
Now, if you edit pkg/mod.py
instead, import pkg.
will correctly suggest mod
. It is as if the file being edited is influencing jedi’s notion of the python path.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python: Unit Testing Module and Relative Imports
Here is a hack* Insert the path's to "subpackage" and "test" to your python path in run_everything using: import sys sys.path.insert(0, ...
Read more >Unit Tests with relative imports broken · Issue #3932 - GitHub
Relative imports result in an "ImportError: attempted relative import with no known parent package" error. This happens, because the directory ...
Read more >Traps for the Unwary in Python's Import System
I'm cross-referencing packages that all reside under 'project' and I hit a problem with an internal import that's using explicit relative imports (i.e....
Read more >Unit test issues with relative imports : r/learnpython - Reddit
Hello! I'm trying to do some unit testing, I'm having some issues with relative imports I think Here I have the test, and...
Read more >Relative Imports in Python - Without Tearing Your Hair Out
Your tests should run just fine now. However this feels really weird - drink_test.py now imports from src by pointing to a location...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Setting PYTHONPATH is not respected in VIMs Python. We could potentially do that in jedi-vim. What do you think @blueyed ?
Latest Jedi is way way smarter about this stuff and thanks to your reproduction case I was able to see that this has been solved.