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

I'm running this command:

    python test project.apps.app1.tests

and it causes this error:

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

Below is my directory structure. I've also added app1 to my installed apps config.

    Traceback (most recent call last):
        File "", line 10, in <module> execute_from_command_line(sys.argv)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/", line 385, in execute_from_command_line
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/", line 377, in execute
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/commands/", line 50, in run_from_argv
        super(Command, self).run_from_argv(argv)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/", line 288, in run_from_argv
        self.execute(*args, **options.__dict__)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/commands/", line 71, in execute
        super(Command, self).execute(*args, **options)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/", line 338, in execute
        output = self.handle(*args, **options)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/commands/", line 88, in handle
        failures = test_runner.run_tests(test_labels)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/test/", line 146, in run_tests
        suite = self.build_suite(test_labels, extra_tests)
        File "/home/username/local/dev/local/lib/python2.7/site-packages/django/test/", line 66, in build_suite
        tests = self.test_loader.loadTestsFromName(label)
        File "/usr/lib/python2.7/unittest/", line 100, in loadTestsFromName
        parent, obj = obj, getattr(obj, part)
        AttributeError: 'module' object has no attribute 'tests'

Directory structure:

enter image description here

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.


    from project.apps.app1.tests import *


Back to homepage or read more recommendations: