Fixed #33278 -- Improved error for connection/query attempts against disallowed databases in tests.

This commit is contained in:
SwastikTripathi 2021-11-12 23:06:13 +05:30 committed by Mariusz Felisiak
parent 560ff988dd
commit 76f07b4fcf
4 changed files with 16 additions and 10 deletions

View file

@ -2,6 +2,7 @@ from unittest import mock
from django.db import connections
from django.test import TestCase, TransactionTestCase, override_settings
from django.test.testcases import DatabaseOperationForbidden
from .models import Car
@ -58,5 +59,5 @@ class DisallowedDatabaseQueriesTests(TransactionTestCase):
"DisallowedDatabaseQueriesTests.databases to ensure proper test "
"isolation and silence this failure."
)
with self.assertRaisesMessage(AssertionError, message):
with self.assertRaisesMessage(DatabaseOperationForbidden, message):
Car.objects.using('other').get()