AttributeError: 'module' object has no attribute 'tests'

I finally figured it out working on another problem. The problem was that my test couldn't find an import.

It looks like you get the above error if your test fails to import. This makes sense because the test suite can't import a broken test. At least I think this is what is going on because I fixed the import within my test file and sure enough it started working.

To validate your test case just try import the test case file in python console.

Example:

from project.apps.app1.tests import *

Use:

./manage.py shell

followed by

import myapp.tests

to find the nature of the import error.


For my case, I need to create an empty __init__.py in my app/tests folder


Steve Bradshaw's example above works for import errors (thanks Steve).

Other type of errors (e.g. ValueError) may also cause

AttributeError: 'module' object has no attribute 'tests'

to see what these errors are

./manage.py shell
from myapp.tests import SomeTestCase
t = SomeTestCase()

I had the same error as Chris. I had deleted an old model, then run tests.py, but another file (views.py) was still trying to import the deleted model.

When I took out the now-obsolete import statement, problem solved.