Просмотр исходного кода

Closes #22317: Clear background queues in tearDown for isolation (#22321)

Martin Hauser 1 месяц назад
Родитель
Сommit
3ee228f69a
2 измененных файлов с 14 добавлено и 0 удалено
  1. 8 0
      netbox/core/tests/test_views.py
  2. 6 0
      netbox/extras/tests/test_api.py

+ 8 - 0
netbox/core/tests/test_views.py

@@ -215,6 +215,14 @@ class BackgroundTaskTestCase(TestCase):
         get_queue('high').connection.flushall()
         get_queue('low').connection.flushall()
 
+    def tearDown(self):
+        super().tearDown()
+
+        # Clear all queues after each test so no leftover jobs leak into the next test suite
+        get_queue('default').connection.flushall()
+        get_queue('high').connection.flushall()
+        get_queue('low').connection.flushall()
+
     def test_background_queue_list(self):
         url = reverse('core:background_queue_list')
 

+ 6 - 0
netbox/extras/tests/test_api.py

@@ -1155,6 +1155,12 @@ class ScriptTestCase(APITestCase):
         # Monkey-patch the Script model to return our TestScriptClass above
         Script.python_class = self.python_class
 
+        # The script-run endpoint gates on a live RQ worker. Tests run without
+        # one, so bypass the check to exercise validation and the enqueue path.
+        worker_patch = patch('extras.api.views.any_workers_for_queue', return_value=True)
+        worker_patch.start()
+        self.addCleanup(worker_patch.stop)
+
     def test_get_script(self):
         response = self.client.get(self.url, **self.header)