From 3ee228f69a14c5c65f4b8855a18681d8daf81d26 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Thu, 28 May 2026 20:57:53 +0200 Subject: [PATCH] Closes #22317: Clear background queues in tearDown for isolation (#22321) --- netbox/core/tests/test_views.py | 8 ++++++++ netbox/extras/tests/test_api.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/netbox/core/tests/test_views.py b/netbox/core/tests/test_views.py index 03569d10b..40dc3b722 100644 --- a/netbox/core/tests/test_views.py +++ b/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') diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 7a87b0d85..df94cbe0d 100644 --- a/netbox/extras/tests/test_api.py +++ b/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)