QasimK
QasimK

Reputation: 425

Testing with TransactionTestCase uses real database

When I test using django.test.TransactionTestCase I have found that it uses the real database.

(django.test.TestCase works normally!)

I have confirmed this in my own project using the simple code:

class TestInventoryTransactions(TransactionTestCase):
    def setUp(self):
        print(Item.objects.all())

    def test1(self):
        pass

    def test2(self):
        pass

The output of this is

[...Bunch of items...]
[]

Showing that firstly that the real database is being used and not an empty test database. Secondly, it removes everything from the database after the first test.

I really don't think this is the expected behaviour and don't see why it would be happening.

Upvotes: 0

Views: 366

Answers (1)

QasimK
QasimK

Reputation: 425

Using "manage.py test" does not have this problem. It only occurs when running the test file manually.

Upvotes: 1

Related Questions