question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong relative imports in unit tests with parallel hierarchy

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davidhaltercommented, Apr 25, 2017

Setting PYTHONPATH is not respected in VIMs Python. We could potentially do that in jedi-vim. What do you think @blueyed ?

0reactions
davidhaltercommented, Dec 27, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found