196๐
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 *
39๐
Use:
./manage.py shell
followed by
import myapp.tests
to find the nature of the import error.
- [Django]-What is the difference between cached_property in Django vs. Python's functools?
- [Django]-Multiple Database Config in Django 1.2
- [Django]-Django count RawQuerySet
- [Django]-Django ManyToMany filter()
- [Django]-Django 2.0 โ Not a valid view function or pattern name (Customizing Auth views)
- [Django]-Where's my JSON data in my incoming Django request?
6๐
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()
- [Django]-Get object by field other than primary key
- [Django]-Using Python's os.path, how do I go up one directory?
- [Django]-NumPy array is not JSON serializable
5๐
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.
- [Django]-IOS app with Django
- [Django]-Complete django DB reset
- [Django]-A Better Django Admin ManyToMany Field Widget
3๐
Make sure that all modules that you are using in your script are not broken. By this I mean check spelling in your import statements.
# invalid import
from app.model.notification import Notification
# valid import
from app.models.notification import Notification
You can test yours modules by executing imports statements in djanoโs interactive console.
$root@13faefes8: python manage.py shell
Type "help", "copyright", "credits" or "license" for more information (InteractiveConsole)
>>> from app.model.notification import Notification
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named model.notification
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-Auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserManage.groups'
- [Django]-<Django object > is not JSON serializable
2๐
I resolved the error โAttributeError: module โutilsโ has no attribute โname_of_my_functionโ โ by fixing a circular import reference. My files manage.py and utils.py each had an import statement pointing at each other.
- [Django]-<Django object > is not JSON serializable
- [Django]-Django โ Website Home Page
- [Django]-How to merge consecutive database migrations in django 1.9+?
2๐
I had the same error. It turned out to be because I named my module common.py, yet there already was some other common.py module. All I had to do was to rename my module.
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-Django migration strategy for renaming a model and relationship fields
- [Django]-UUID as default value in Django model
1๐
According to django document When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.TestCase) in any file whose name begins with test, automatically build a test suite out of those test cases, and run that suite.
so try this : python manage.py test tests.py
- [Django]-Django switching, for a block of code, switch the language so translations are done in one language
- [Django]-Django โ makemigrations โ No changes detected
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
1๐
Got the same error, but checked all the reasons list here, did not fix my problem.
Finally figure it out that, the reason is that the name of one method that imported but not used yet is not correct. Though it is a stupid error, it happens.
- [Django]-How to get the name of current app within a template?
- [Django]-Django: guidelines for speeding up template rendering performance
- [Django]-Django set field value after a form is initialized
0๐
I had a similar error while writing a unittest.TestCase.
When I re-typed the same method definition as-is, it seemed to work !
The only change I noticed on PyCharm was the โoverrideโ icon pop-up the 2nd time, as the setup(self) method needs to override the original method defined in TestCase.
- [Django]-Django CSRF check failing with an Ajax POST request
- [Django]-Django: Safely Remove Old Migrations?
- [Django]-Django Form File Field disappears on form error
- [Django]-Multiple ModelAdmins/views for same model in Django admin
- [Django]-How to do SELECT MAX in Django?
- [Django]-Django Rest Framework โ Could not resolve URL for hyperlinked relationship using view name "user-detail"