Last active
June 9, 2019 15:47
-
-
Save maxpoletaev/05e9e63674bf9efc064ad72d12653481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import mock | |
from django.test import TestCase | |
from django.db import transaction | |
class TransactionCommitHooksMixin: | |
""" | |
Fake transaction commit to run delayed on_commit functions | |
https://medium.com/gitux/speed-up-django-transaction-hooks-tests-6de4a558ef96 | |
""" | |
def run_commit_hooks(self: TestCase): | |
for db_name in reversed(self._databases_names()): | |
with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.validate_no_atomic_block', | |
lambda a: None): | |
transaction.get_connection(using=db_name).run_and_clear_commit_hooks() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment