|
5 | 5 | import unittest |
6 | 6 | import uuid |
7 | 7 | from ast import literal_eval |
| 8 | +from contextlib import contextmanager |
8 | 9 |
|
9 | 10 | from lxml import etree |
10 | 11 |
|
|
13 | 14 | except ImportError: |
14 | 15 | import mock |
15 | 16 |
|
| 17 | +from odoo import modules |
16 | 18 | from odoo.tools import mute_logger |
17 | 19 | from odoo.tools.safe_eval import safe_eval |
18 | 20 |
|
|
31 | 33 | NOTNOT = () if USE_ORM_DOMAIN else ("!", "!") |
32 | 34 |
|
33 | 35 |
|
| 36 | +@contextmanager |
| 37 | +def without_testing(): |
| 38 | + thread = threading.current_thread() |
| 39 | + testing = getattr(modules.module, "current_test", False) or getattr(thread, "testing", False) |
| 40 | + try: |
| 41 | + modules.module.current_test = False |
| 42 | + thread.testing = False |
| 43 | + yield |
| 44 | + finally: |
| 45 | + thread.testing = testing |
| 46 | + modules.module.current_test = testing |
| 47 | + |
| 48 | + |
34 | 49 | class TestAdaptOneDomain(UnitTestCase): |
35 | 50 | def setUp(self): |
36 | 51 | super(TestAdaptOneDomain, self).setUp() |
@@ -754,9 +769,8 @@ def test_parallel_rowcount(self): |
754 | 769 | self.assertEqual(rowcount, expected) |
755 | 770 |
|
756 | 771 | def test_parallel_rowcount_threaded(self): |
757 | | - threading.current_thread().testing = False |
758 | | - self.test_parallel_rowcount() |
759 | | - threading.current_thread().testing = True |
| 772 | + with without_testing(): |
| 773 | + self.test_parallel_rowcount() |
760 | 774 |
|
761 | 775 | def test_parallel_execute_retry_on_serialization_failure(self): |
762 | 776 | TEST_TABLE_NAME = "_upgrade_serialization_failure_test_table" |
@@ -786,13 +800,11 @@ def test_parallel_execute_retry_on_serialization_failure(self): |
786 | 800 | ) |
787 | 801 | ) |
788 | 802 |
|
789 | | - threading.current_thread().testing = False |
790 | 803 | # exploded queries will generate a SerializationFailed error, causing some of the queries to be retried |
791 | | - with mute_logger(util.pg._logger.name, "odoo.sql_db"): |
| 804 | + with without_testing(), mute_logger(util.pg._logger.name, "odoo.sql_db"): |
792 | 805 | util.explode_execute( |
793 | 806 | cr, util.format_query(cr, "DELETE FROM {}", TEST_TABLE_NAME), TEST_TABLE_NAME, bucket_size=1 |
794 | 807 | ) |
795 | | - threading.current_thread().testing = True |
796 | 808 |
|
797 | 809 | if hasattr(self, "_savepoint_id"): |
798 | 810 | # `explode_execute` causes the cursor to be committed, losing the automatic checkpoint |
|
0 commit comments