First, it's pretty confusing to have my_module and my_module/my_module, but let's ignore that.
In order for my_module to work, the outer my_module has to be on your sys.path.
So, if you do this:
$ cd tests
$ python tests.py
… then your sys.path will just by your usual path, plus my_module/tests. It won't include my_module, so you can't find my_module/my_module anywhere.
Ways around this include:
- Have a top-level test.pythat doesfrom tests import tests.pyandtests.run().
- Run you code as python -m tests.testsfrom the top-levelmy_moduledirectory, instead of running it aspython tests.pyfrommy_module/tests.
- Have tests/tests.pyinsertos.path.join(__path__, '../my_module) intosys.pathmanually.
- Use setuptools/pkg_resourcesinstead of trying to do everything manually.
- Do the hacky old-style thing described here. (You really don't want to do this unless you need to be compatible with Python 2.7 or 3.2 or old distribute/distutilsversions ofpkg_resources.)
 
    
__init__files?