#30457: on_commit should be triggered in a TestCase
------------------------------------+-------------------------------------
Reporter: Bernhard Mäder | Owner: Swatantra
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: on_commit TestCase | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------------+-------------------------------------
Comment (by Dylan Young):
Here's a mixin for your TestCases:
{{{
class ImmediateOnCommitMixin(object):
"""
TODO: Remove when immediate_on_commit function is actually implemented
Django Ticket #: 30456, Link:
https://code.djangoproject.com/ticket/30457#no1
"""
@classmethod
def setUpClass(cls):
super(ImmediateOnCommit, cls).setUpClass()
def immediate_on_commit(func, using=None):
func()
# Context manager executing transaction.on_commit() hooks
immediately
# This is required when using a subclass of django.test.TestCase
as all tests are wrapped in
# a transaction that never gets committed.
cls.on_commit_mgr = mock.patch('django.db.transaction.on_commit',
side_effect=immediate_on_commit)
cls.on_commit_mgr.__enter__()
@classmethod
def tearDownClass(cls):
super(ImmediateOnCommit, cls).tearDownClass()
cls.on_commit_mgr.__exit__()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30457#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.eda1c364afae143a71d81726ef682ab7%40djangoproject.com.