Suppress extraneous logging in BackgroundTaskTestCase

This commit is contained in:
Jeremy Stretch 2025-05-16 12:47:05 -04:00
parent 3f3d379a1c
commit b8c0c0faeb

View File

@ -14,7 +14,7 @@ from core.choices import ObjectChangeActionChoices
from core.models import * from core.models import *
from dcim.models import Site from dcim.models import Site
from users.models import User from users.models import User
from utilities.testing import TestCase, ViewTestCases, create_tags from utilities.testing import TestCase, ViewTestCases, create_tags, disable_logging
class DataSourceTestCase(ViewTestCases.PrimaryObjectViewTestCase): class DataSourceTestCase(ViewTestCases.PrimaryObjectViewTestCase):
@ -271,6 +271,7 @@ class BackgroundTaskTestCase(TestCase):
# Enqueue & run a job that will fail # Enqueue & run a job that will fail
job = queue.enqueue(self.dummy_job_failing) job = queue.enqueue(self.dummy_job_failing)
worker = get_worker('default') worker = get_worker('default')
with disable_logging():
worker.work(burst=True) worker.work(burst=True)
self.assertTrue(job.is_failed) self.assertTrue(job.is_failed)
@ -317,6 +318,7 @@ class BackgroundTaskTestCase(TestCase):
self.assertEqual(len(started_job_registry), 1) self.assertEqual(len(started_job_registry), 1)
response = self.client.get(reverse('core:background_task_stop', args=[job.id])) response = self.client.get(reverse('core:background_task_stop', args=[job.id]))
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
with disable_logging():
worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started
self.assertEqual(len(started_job_registry), 0) self.assertEqual(len(started_job_registry), 0)