Reputation: 2476
I have directory which has a app and it has corresponding test script files in 'tests' directory.
project/
--myapp/
--__init__.py(<-- updated)
--tests/
--tests1.py
--tests2.py etc
--run_tests.py
runtests.py
traverses 'tests' directory recursively and executes all python scripts in it.
tests*.py
has to import myapp for the tests to run. Since, tests*.py
files are in 'tests' directory, it doesn't work.
How do I make 'myapp' to be available to all tests*.py
files in 'tests' directory? I think there would be simple solution than setting 'myapp' in PYTHONPATH.
Note: nosetests tests/
will work. So, just curious on how it works.
Thanks in advance.
Upvotes: 0
Views: 110
Reputation: 46350
if myapp
is in pythonpath:
from myapp import mymodule
You can also do relative imports:
from .. import mymodule
Upvotes: 1
Reputation: 5356
Python has a feature that makes a directory a package (init.py). With that, each .py file becomes a part of this module.
try checking this post
Upvotes: 0