Error when importing models into test.py file, django

I'm trying to create a test.py file for some of my database methods in a current django project. I need to import my models.py file, but the import statement I'm using below (which follows the official Django example) is causing an error. Both test.py and models.py are already in appFolder, so is that the issue?

from appFolder.models import Class1,Class2,Class3 

Using only 'import models' didn't work when I ran it earlier. How can I resolve this? (I have also been running the file with the command './manage.py test' if that's relevant)

If you have files in the same folder, you can use relative imports. Here is the example code:

from .models import Class1

There might be several problems but possibly you have missed the app inside the INSTALLED_APPS list in your settings file. That is a common mistake but relative imports work fine if you can manually trigger the tests.

Back to Top