I am trying to make a stand-alone application in Python and there are some problems related to imports and the project's directory structure that I do not how to solve.
This is how the project is structured:
root/
app/
__init__.py
main.py
foo.py
tests/
__init__.py
main_tests.py
foo_tests.py
These are the two conflicting requirements which I don't know how to solve:
The tests are written using the Nose framework. When I run
nosetests
from theroot
directory, it requires all imports to be relative to theapp
package.# app/main.py import app.foo # `import foo` will not work
On the other hand, if I want to run the application from
root
(with a command likepython app/main.py
), another problem occurs. It will rightly complain that it cannot find theapp
package.
How can I fix these problems? Is there anything I need to change in how I organized my project?