Reputation: 2783
Environment: Intellij PyCharm, Python Django, Sqlite3
I use a standard Django setup project. I try to write some Unittests, but I run into the following error. After some research, I ended up here.
DB Config
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Code of tests.py
from django.test import TestCase as djangoTestCase
import os
import unittest
# Create your tests here.
class TestExample(djangoTestCase):
def setUp(self):
print('setup')
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_abc(self):
self.assertEqual(1,1)
def tearDown(self):
print('tearDown')
if __name__ == '__main__':
unittest.main()
This is the output
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I tried to find the mistake by reading documentation, but without success. What could be the problem?
Upvotes: 1
Views: 582
Reputation: 4467
I ran into the same problem in PyCharm. My DB config is in file config.settings_dev
. By default, PyCharm is not aware of it.
To solve it,
Run
-> Edit Configurations
Templates
, then Djano tests
.DJANGO_SETTINGS_MODULE
with value config.settings_dev
(replace it with your own settings file)Django tests
Upvotes: 1
Reputation: 47354
With django test you don't need this part:
if __name__ == '__main__':
unittest.main()
you just running tests with python manage.py test
command.
Upvotes: 1