What you are trying to do is relative imports. It works fine in Python, but at the module level, and not at the file system level. I know this is confusing.
This means that if you run the script in a subdirectory, it does not see the upper sections, because to run the script, the module root is the current director: there is no top module.
So what is relative imports for?
Well, the module in the module import cars subdirs in the upper rows, if they themselves are imported from the upper level.
In your case, this means that you must run your scripts from "/" so that it becomes the root of the module, and submodules are allowed to use relative imports.
A possible solution to your problem is to remove the if __name__ == "__main__" block and create /tests.py:
import doctest from model import car from tools import tool doctest.testmod(car) doctest.testmod(tool)
Then run all the tests as well.
Ultimately, you'll want to automate the process, a simple solution is to use unittest so you can create test packages and just add the names of the modules you want to test:
import unittest import doctest modules = ("model.car", "tools.tool") suite = unittest.TestSuite() for mod in modules: suite.addTest(doctest.DocTestSuite(mod)) runner = unittest.TextTestRunner() runner.run(suite)
Another solution (recommended) is to use a tool such as nose that automates this for you.
easy_install nose nosetests --with-doctest
And by the way, avoid from x import * . This works for fast scripts, but when your program grows, you really need to explicitly specify what you are importing. Either import x , or from x import y