How to structure imports to make debugger and tests work at the same time? #24509
Unanswered
Scott Rubin (Apreche)
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have a Python project that is comprised of several small individual projects. The directory structure looks something like this.
If I work on this project in VSCode, I would like three things to be true.
$ python test_code.pytest_code.pyfiles and run them properly.Here is the problem.
The
test_code.pyfiles must necessarily import their accompanyingcode.pyfiles in order to call and test the code they contain.If I write the imports in the form
import codethen everything works fine if I run Python from the terminal or launch the VSCode debugger. However, the Python test module does not work. It fails to discover the tests. There is an errorModuleNotFoundError: No module named 'code'If I change the imports to the relative form
from . import codethen the VSCode Python test module works. It is able to discover and run all the tests properly. However, trying to run the test file using the debugger or using Python in the terminal no longer works. It gives an errorImportError: attempted relative import with no know parent package.How can I structure the imports to make all of these things work at the same time?
All reactions