9

I am running tests in my newly created Django project.

Normally I would expect to see a test database created for when tests are running. All tests are running fine, but I am seeing that my local database (for runserver use) is beeing used when running the tests.

A lot of excess data is beeing created in the wrong database. How can I get my test setup to use the normal test_dabasename setup again?

Im not sure what I have changed to make this happen and am totally stumped.

class TestRest(TestCase):
    def setUp(self):
        ...

    def test_allowed_to_get_list_authenticated(self):
        ....
2
  • please check this ticket it has similar answer for your question stackoverflow.com/a/4650651/6365947 Commented Jul 28, 2020 at 13:50
  • @issamabbas I can go in and edit the project.settings.test config with data like that, but then I get other errors, for example: DATABASES["default"] = {"ENGINE": "django.db.backends.sqlite3", "NAME": "mydatabase"} leads to django.db.utils.OperationalError: no such table: base_user and DATABASES["default"]["NAME"] = f"test_{os.getenv('DB_NAME')}" leads to database "test_mitt_se" does not exist Commented Jul 29, 2020 at 6:19

1 Answer 1

18

Found it. Im such a bad programmer :(.

I imported from

from unittest.case import TestCase

when it should have been

from django.test import TestCase

This lead to no test database beeing created.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.