Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Django transaction management for issue #226 #278

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions django_nose/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ def setUpClass(cls):
raise NotImplementedError('%s supports only DBs with transaction '
'capabilities.' % cls.__name__)
for db in cls._databases():
# These MUST be balanced with one leave_* each:
transaction.enter_transaction_management(using=db)
# Don't commit unless we say so:
transaction.managed(True, using=db)
transaction.set_autocommit(False, using=db)

cls._fixture_setup()

Expand All @@ -59,15 +57,14 @@ def tearDownClass(cls):
for db in cls._databases():
# Finish off any transactions that may have happened in
# tearDownClass in a child method.
if transaction.is_dirty(using=db):
transaction.commit(using=db)
transaction.leave_transaction_management(using=db)
transaction.commit(using=db)

@classmethod
def _fixture_setup(cls):
"""Load fixture data, and commit."""
for db in cls._databases():
if (hasattr(cls, 'fixtures') and
cls.fixtures is not None and
getattr(cls, '_fb_should_setup_fixtures', True)):
# Iff the fixture-bundling test runner tells us we're the first
# suite having these fixtures, set them up:
Expand Down Expand Up @@ -122,8 +119,6 @@ def _pre_setup(self):
cache.cache.clear()
settings.TEMPLATE_DEBUG = settings.DEBUG = False

test.testcases.disable_transaction_methods()

self.client = self.client_class()
# self._fixture_setup()
self._urlconf_setup()
Expand All @@ -142,7 +137,6 @@ def _post_teardown(self):

"""
# Rollback any mutations made by tests:
test.testcases.restore_transaction_methods()
for db in self._databases():
transaction.rollback(using=db)

Expand Down