mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Avoided transaction.set_autocommit in tests.
It doesn't work as one might expect on a certain database backend where
autocommits_when_autocommit_is_off = True. That backend happens to be
popular for running tests.
Backport of 38bc581bc0 from master.
This commit is contained in:
@@ -660,22 +660,15 @@ class TestTicket11101(TransactionTestCase):
|
||||
'django.contrib.contenttypes',
|
||||
]
|
||||
|
||||
def ticket_11101(self):
|
||||
management.call_command(
|
||||
'loaddata',
|
||||
'thingy.json',
|
||||
verbosity=0,
|
||||
)
|
||||
self.assertEqual(Thingy.objects.count(), 1)
|
||||
transaction.rollback()
|
||||
self.assertEqual(Thingy.objects.count(), 0)
|
||||
transaction.commit()
|
||||
|
||||
@skipUnlessDBFeature('supports_transactions')
|
||||
def test_ticket_11101(self):
|
||||
"""Test that fixtures can be rolled back (ticket #11101)."""
|
||||
transaction.set_autocommit(False)
|
||||
try:
|
||||
self.ticket_11101()
|
||||
finally:
|
||||
transaction.set_autocommit(True)
|
||||
with transaction.atomic():
|
||||
management.call_command(
|
||||
'loaddata',
|
||||
'thingy.json',
|
||||
verbosity=0,
|
||||
)
|
||||
self.assertEqual(Thingy.objects.count(), 1)
|
||||
transaction.set_rollback(True)
|
||||
self.assertEqual(Thingy.objects.count(), 0)
|
||||
|
||||
Reference in New Issue
Block a user