What does "'tests' module incorrectly imported" mean?

Try checking whether you have both a app/tests folder and a app/tests.py

file in your app.

By default a file is automatically called tests.py delete this file it the error will be resolved


As Daniel Hepper said in a comment above, try checking whether you have both a app/tests folder and a app/tests.py file in your app.

Django startapp creates a tests.py file automatically so there might be a file that you haven't noticed.

If you simply delete the automatically generated tests.py file, it should work. (Obviously you should check the contents of the file before deleting anything!)


In case you have created a directory named tests and have written test files inside it, for example test_views.py, test_models.py, etc., make sure you remove the file test.py created automatically by the command python manage.py startapp.


In my experience, weird ImportErrors when running tests are caused by an ImportError in the tests module itself.

Ensure that your tests module can be imported:

$ python manage.py shell
...
>>> import foo.exports.tests

Edit:

If that causes an error, make sure you do not have both a directory foo/exports/tests and a file foo/exports/tests.py

Tags:

Python

Django