Suppress extraneous logging in BackgroundTaskTestCase

This commit is contained in:
Jeremy Stretch 2025-05-16 09:51:50 -04:00
parent b6c8502408
commit 26091cfa87

View File

@ -9,6 +9,7 @@ from rq.registry import FailedJobRegistry, StartedJobRegistry
from users.models import Token, User from users.models import Token, User
from utilities.testing import APITestCase, APIViewTestCases, TestCase from utilities.testing import APITestCase, APIViewTestCases, TestCase
from utilities.testing.utils import disable_logging
from ..models import * from ..models import *
@ -189,7 +190,8 @@ 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')
worker.work(burst=True) with disable_logging():
worker.work(burst=True)
self.assertTrue(job.is_failed) self.assertTrue(job.is_failed)
# Re-enqueue the failed job and check that its status has been reset # Re-enqueue the failed job and check that its status has been reset
@ -231,7 +233,8 @@ class BackgroundTaskTestCase(TestCase):
self.assertEqual(job.get_status(), JobStatus.STARTED) self.assertEqual(job.get_status(), JobStatus.STARTED)
response = self.client.post(reverse('core-api:rqtask-stop', args=[job.id]), **self.header) response = self.client.post(reverse('core-api:rqtask-stop', args=[job.id]), **self.header)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started with disable_logging():
worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started
started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection) started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection)
self.assertEqual(len(started_job_registry), 0) self.assertEqual(len(started_job_registry), 0)