File tree Expand file tree Collapse file tree 3 files changed +19
-18
lines changed
Expand file tree Collapse file tree 3 files changed +19
-18
lines changed Original file line number Diff line number Diff line change 1+ import logging
2+
13import orjson
24from dramatiq import set_broker , set_encoder
35from dramatiq .broker import Broker
@@ -26,15 +28,17 @@ def decode(self, data: bytes) -> MessageData:
2628
2729
2830def init_dramatiq (config : AppConfig ):
29- DramatiqInstrumentor ().instrument ()
3031 broker : Broker
31- if config . ENVIRONMENT == "test" :
32- broker = StubBroker ()
33- # broker.emit_after("process_boot")
34- elif config .DRAMATIQ .REDIS_URL is not None :
32+
33+ DramatiqInstrumentor (). instrument ()
34+
35+ if config .DRAMATIQ .REDIS_URL is not None :
3536 broker = RedisBroker (url = config .DRAMATIQ .REDIS_URL )
3637 else :
37- raise RuntimeError ("Running a non-test environment without Redis URL set" )
38+ broker = StubBroker ()
39+ # broker.emit_after("process_boot")
40+ if config .ENVIRONMENT != "test" :
41+ logging .critical ("Running a non-test environment without Redis URL set" )
3842 broker .add_middleware (AsyncIO ())
3943 set_broker (broker )
4044 set_encoder (ORJSONEncoder ())
Original file line number Diff line number Diff line change 1+ import logging
12from unittest .mock import MagicMock , patch
23
34import orjson
@@ -61,12 +62,12 @@ def test_init_dramatiq_with_redis():
6162 assert isinstance (get_encoder (), ORJSONEncoder )
6263
6364
64- def test_init_dramatiq_without_redis_url ():
65+ def test_init_dramatiq_without_redis_url (caplog ):
6566 """Test if an exception is raised when in non-test environment without Redis URL."""
6667 config = AppConfig (
6768 ENVIRONMENT = "production" , DRAMATIQ = DramatiqConfig (REDIS_URL = None )
6869 ) # Mock config
69- with pytest .raises (
70- RuntimeError , match = "Running a non-test environment without Redis URL set"
71- ):
70+ with caplog .at_level (logging .CRITICAL ):
7271 init_dramatiq (config )
72+
73+ assert "Running a non-test environment without Redis URL set" in caplog .text
Original file line number Diff line number Diff line change 11from unittest .mock import patch
22
3- import pytest
4-
53from common .config import AppConfig
64from http_app import create_app
75
86
97def test_with_default_config () -> None :
10- """Test create_app fails without passing test config."""
11- with (
12- patch ("common.bootstrap.init_storage" , return_value = None ),
13- pytest .raises (RuntimeError ),
14- ):
15- create_app ()
8+ """Test create_app without passing test config."""
9+ with patch ("common.bootstrap.init_storage" , return_value = None ):
10+ app = create_app ()
11+ assert app .debug is False
1612
1713
1814def test_with_debug_config () -> None :
You can’t perform that action at this time.
0 commit comments