Why will my unit tests only run on a my apps, not my entire project?
Question: I've just started writing my first unit tests for a django project, but have
come across an issue when attempting to run all the projects tests.

If I run the tests for a specific module/app it works fine:

    
    
    ./manage.py test my_project.api --settings=my_project.settings.test
    

But when I attempt to run all tests in the project:

    
    
    ./manage.py test my_project --settings=my_project.settings.test
    

I get an error for every tests.py that's found:

    
    
    ======================================================================
    ERROR: my_project.api.tests.tests (unittest.loader.ModuleImportFailure)
    ----------------------------------------------------------------------
    ImportError: Failed to import test module: my_project.api.tests.tests
    Traceback (most recent call last):
        File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 252, in _find_tests
            module = self._get_module_from_name(name)
         File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
            __import__(name)
    ImportError: No module named my_project.api.tests.tests
    

I am using virtualenvwrapper with the following,

python 2.7.1

django 1.6.1

Anyone know why this might be happening?

**EDIT**

This is an abbreviated view of my project structure:

    
    
    my_project_root
        |
        |
        |--- my_project
        |        |
        |        |--- api
        |        |     |
        |        |      ---- tests
        |        |             |
        |        |              --- tests.py
        |        |--- core
        |        |     |
        |        |       ---- tests
        |        |              |
        |        |               --- tests.py
        |         --- settings
        |                |
        |                 ---- test.py
        |
        |
         --- manage.py
    

Reading the django docs,

"Test discovery is based on the unittest module's built-in test discovery. By
default, this will discover tests in any file named “test*.py” under the
current working directory."

Which is /my_project_root/


Answer: This problem was (partially) solved within the comments, it was a combination
of an environment configuration error and how test discovery works.

Put simply, `__init__.py` should not be present within `my_project_root`.

To make heroku be able to discover `wsgi.py`, the `$PYTHONPATH` environment
variable should be adjusted to include `my_project_root`.

Additionally, you can specify

    
    
    heroku config:set WSGI_PATH=path/to/my/file/wsgi.py
    

