Coverage for app/venv/lib/python3.14/site-packages/weblate/utils/django_hacks.py: 0%
8 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5from unittest import mock
8def immediate_on_commit(cls) -> None:
9 """
10 Execute transaction.on_commit immediately.
12 This is alternative approach to TestCase.captureOnCommitCallbacks() which
13 was implemented Django Ticket https://code.djangoproject.com/ticket/30457
14 """
16 def handle_immediate_on_commit(func, using=None) -> None:
17 func()
19 # Context manager executing transaction.on_commit() hooks immediately
20 # This is required when using a subclass of django.test.TestCase as all tests
21 # are wrapped in a transaction that never gets committed.
22 cls.on_commit_mgr = mock.patch(
23 "django.db.transaction.on_commit", side_effect=handle_immediate_on_commit
24 )
25 cls.on_commit_mgr.start()
28def immediate_on_commit_leave(cls) -> None:
29 cls.on_commit_mgr.stop()