Think about what's on your PYTHONPATH . The toplevel package for your project is my_project , so this should be the beginning of any import for something in your project.
from my_project.foo import bar
You can also use relative imports, although this is not so clear and breaks if you ever change the relative location of the module from which you performed this import.
from ..foo import bar
Ideally, the test folder is not a package and is not part of your application package. See the pytests page for good practice . This requires that you add setup.py to your package and install it in your virtual mode in development mode.
pip install -e .
Do not run tests by pointing directly to the file in your application. After properly structuring / installing your project, use the discovery engine for any structure you use to run tests for you. For example, using pytest just specify the test folder:
pytest tests
Or for the unittest built-in module:
python -m unittest discover -s tests
source share