Desired directory tree:
Fibo
|-- src
| `-- Fibo.py
`-- test
`-- main.py
What I want is to call python main.py after cd’ing into test and executing main.py will run all the unit tests for this package.
Currently if I do:
import Fibo
def main():
Fibo.fib(100)
if __name__ == "__main__":
main()
I get an error: “ImportError: No module named Fibo“.
But if I do:
import sys
def main():
sys.path.append("/home/tsmith/svn/usefuldsp/trunk/Labs/Fibo/src")
import Fibo
Fibo.fib(100)
if __name__ == "__main__":
main()
This seems to fix my error. And I could move forward… but this isn’t a python package. This is more of a “collection of files” approach.
How would you setup your testing to work in this directory structure?
If I want to import a module that lives at a fixed, relative location to the file I’m evaluating, I often do something like this:
If you want to be a good namespace-citizen, you could
delthe no longer needed symbols at the end of theexceptblock.