Skip to content

Commit 31eb204

Browse files
committed
Use override_settings in tests where we can now do so
This slightly changes the behaviour of the mock_workers helpers, however the default is an empty dictionary so this feels like a reasonable trade-off for using the more standard override_settings util.
1 parent ccd9992 commit 31eb204

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

tests/test_pause_resume.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import io
22
import datetime
3-
import unittest
43
from unittest import mock
54

65
import fakeredis
76
import freezegun
87

8+
from django.test import SimpleTestCase, override_settings
99
from django.core.management import call_command, CommandError
1010

1111
from django_lightweight_queue.types import QueueName
@@ -18,7 +18,7 @@
1818
)
1919

2020

21-
class PauseResumeTests(unittest.TestCase):
21+
class PauseResumeTests(SimpleTestCase):
2222
longMessage = True
2323

2424
def assertPaused(self, queue: QueueName, context: str) -> None:
@@ -49,11 +49,8 @@ def setUp(self) -> None:
4949

5050
super().setUp()
5151

52-
# Can't use override_settings due to the copying of the settings values into
53-
# module values at startup.
54-
@mock.patch(
55-
'django_lightweight_queue.app_settings.Defaults.BACKEND',
56-
new='django_lightweight_queue.backends.redis.RedisBackend',
52+
@override_settings(
53+
LIGHTWEIGHT_QUEUE_BACKEND='django_lightweight_queue.backends.redis.RedisBackend',
5754
)
5855
def test_pause_resume(self) -> None:
5956
QUEUE = QueueName('test-pauseable-queue')

tests/test_reliable_redis_backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import fakeredis
1010

11+
from django.test import SimpleTestCase, override_settings
12+
1113
from django_lightweight_queue.job import Job
1214
from django_lightweight_queue.types import QueueName
1315
from django_lightweight_queue.backends.reliable_redis import (
@@ -18,7 +20,7 @@
1820
from .mixins import RedisCleanupMixin
1921

2022

21-
class ReliableRedisDeduplicationTests(RedisCleanupMixin, unittest.TestCase):
23+
class ReliableRedisDeduplicationTests(RedisCleanupMixin, SimpleTestCase):
2224
longMessage = True
2325
prefix = settings.LIGHTWEIGHT_QUEUE_REDIS_PREFIX
2426

@@ -49,9 +51,8 @@ def mock_workers(self, workers: Mapping[str, int]) -> Iterator[None]:
4951
with unittest.mock.patch(
5052
'django_lightweight_queue.utils._accepting_implied_queues',
5153
new=False,
52-
), unittest.mock.patch.dict(
53-
'django_lightweight_queue.app_settings.app_settings.WORKERS',
54-
workers,
54+
), override_settings(
55+
LIGHTWEIGHT_QUEUE_WORKERS=workers,
5556
):
5657
yield
5758

tests/test_task.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import fakeredis
77

8+
from django.test import SimpleTestCase, override_settings
9+
810
from django_lightweight_queue import task
911
from django_lightweight_queue.types import QueueName, WorkerNumber
1012
from django_lightweight_queue.utils import get_path, get_backend
@@ -20,7 +22,8 @@ def dummy_task(num: int) -> None:
2022
pass
2123

2224

23-
class TaskTests(unittest.TestCase):
25+
@override_settings(LIGHTWEIGHT_QUEUE_BACKEND='test-backend')
26+
class TaskTests(SimpleTestCase):
2427
longMessage = True
2528
prefix = settings.LIGHTWEIGHT_QUEUE_REDIS_PREFIX
2629

@@ -29,9 +32,8 @@ def mock_workers(self, workers: Mapping[str, int]) -> Iterator[None]:
2932
with unittest.mock.patch(
3033
'django_lightweight_queue.utils._accepting_implied_queues',
3134
new=False,
32-
), unittest.mock.patch.dict(
33-
'django_lightweight_queue.app_settings.Defaults.WORKERS',
34-
workers,
35+
), override_settings(
36+
LIGHTWEIGHT_QUEUE_WORKERS=workers,
3537
):
3638
yield
3739

@@ -53,12 +55,6 @@ def mocked_get_path(path: str) -> Any:
5355
return lambda: self.backend
5456
return get_path(path)
5557

56-
patch = mock.patch(
57-
'django_lightweight_queue.app_settings.Defaults.BACKEND',
58-
new='test-backend',
59-
)
60-
patch.start()
61-
self.addCleanup(patch.stop)
6258
patch = mock.patch(
6359
'django_lightweight_queue.utils.get_path',
6460
side_effect=mocked_get_path,

0 commit comments

Comments
 (0)