Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django not creating a testdatabase when testing

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):
        ....
like image 589
Andreas Avatar asked Jul 28 '20 13:07

Andreas


People also ask

Does Django use Pytest or unittest?

Helps you write better programs. Many developers from Python community heard of and used unit testing to test their projects and knew about boilerplate code with Python and Django unittest module. But Pytest suggests much more pythonic tests without boilerplate.

How do I run test PY?

If you're using the PyCharm IDE, you can run unittest or pytest by following these steps: In the Project tool window, select the tests directory. On the context menu, choose the run command for unittest . For example, choose Run 'Unittests in my Tests…'.


1 Answers

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.

like image 170
Andreas Avatar answered Oct 13 '22 00:10

Andreas