This is currently the way I'm organizing it.
myProject/ README subproject1/ __init__.py classA.py classB.py driver.py basicTest.py
Driver imports from classA and classB and provides some additional functionality. basicTest also imports from Driver and classA.
I've been using
nosetests to discover and run all the tests from basicTest.py. That works great if I'm in the subproject1 directory. However, it doesn't work if I'm in the toplevel myProject directory. The imports fail since the relative paths are then all wrong. I need to run nosetests from the top directory since I'm integrating Travis-CI and it runs nosetests from the top level.
It seems like numpy does all imports relative to the top directory. But, then I can't run the tests from any of the subdirectories, which can be annoying.
Looking around it seems like the only way to make the tests runnable from both directories would be to mess with sys.path at the top of basicTest.py. That seems like a bad idea. This suggests what also seems to be a hacky solution.
Is there a clean solution out there, or is the best approach to just import everything relative to the root and run all the tests from there?
Update: I decided a temporary solution would be to tell Travis-CI to cd into
subproject1 and then run nosetests. This required the fewest number of changes on my part to get everything working. It feels funny though and I'm still looking for a better layout.