diff --git a/apps/backend/tests/view/test_get_gse_config.py b/apps/backend/tests/view/test_get_gse_config.py index 9f7c6cd77..b46cc3876 100644 --- a/apps/backend/tests/view/test_get_gse_config.py +++ b/apps/backend/tests/view/test_get_gse_config.py @@ -11,6 +11,8 @@ import copy +from django.db import transaction + from apps.backend.constants import REDIS_AGENT_CONF_KEY_TPL from apps.backend.utils.redis import REDIS_INST from apps.backend.views import generate_gse_config @@ -30,7 +32,8 @@ def setUpTestData(cls): super().setUpTestData() host_model_data = copy.deepcopy(common_unit.host.HOST_MODEL_DATA) - cls.host = models.Host.objects.create(**host_model_data) + with transaction.atomic(): + cls.host = models.Host.objects.create(**host_model_data) # 此类查询在单元测试中会有如下报错, 因此将数据预先查询缓存 # TransactionManagementError "You can't execute queries until the end of the 'atomic' block" while using signals # 参考:https://stackoverflow.com/questions/21458387