mirror of
https://github.com/django/django.git
synced 2025-08-31 15:57:45 +00:00
Fixed #11665 -- Made TestCase check deferrable constraints after each test.
This commit is contained in:
parent
a6f856df52
commit
fcd08c1757
5 changed files with 50 additions and 2 deletions
20
tests/test_utils/test_testcase.py
Normal file
20
tests/test_utils/test_testcase.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.db import IntegrityError, transaction
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import PossessedCar
|
||||
|
||||
|
||||
class TestTestCase(TestCase):
|
||||
|
||||
@skipUnlessDBFeature('can_defer_constraint_checks')
|
||||
@skipUnlessDBFeature('supports_foreign_keys')
|
||||
def test_fixture_teardown_checks_constraints(self):
|
||||
rollback_atomics = self._rollback_atomics
|
||||
self._rollback_atomics = lambda connection: None # noop
|
||||
try:
|
||||
car = PossessedCar.objects.create(car_id=1, belongs_to_id=1)
|
||||
with self.assertRaises(IntegrityError), transaction.atomic():
|
||||
self._fixture_teardown()
|
||||
car.delete()
|
||||
finally:
|
||||
self._rollback_atomics = rollback_atomics
|
Loading…
Add table
Add a link
Reference in a new issue