1- from unittest .mock import patch , MagicMock
2- from dramatiq .encoder import DecodeError
3- from dramatiq import get_broker , get_encoder
4- from dramatiq .brokers .stub import StubBroker
1+ from unittest .mock import MagicMock , patch
52
6- import pytest
73import orjson
4+ import pytest
5+ from dramatiq import get_broker , get_encoder
6+ from dramatiq .brokers .stub import StubBroker
7+ from dramatiq .encoder import DecodeError
88
99from common import AppConfig
1010from common .config import DramatiqConfig
@@ -27,7 +27,10 @@ def test_orjson_encoder(
2727 mocked_loads .assert_called_once_with (b"serialized" )
2828
2929
30- @patch ("common.dramatiq.orjson.loads" , side_effect = orjson .JSONDecodeError ("msg" ,"doc" , 123 ))
30+ @patch (
31+ "common.dramatiq.orjson.loads" ,
32+ side_effect = orjson .JSONDecodeError ("msg" , "doc" , 123 ),
33+ )
3134def test_orjson_encoder_fails (
3235 mocked_loads : MagicMock ,
3336):
@@ -60,6 +63,10 @@ def test_init_dramatiq_with_redis():
6063
6164def test_init_dramatiq_without_redis_url ():
6265 """Test if an exception is raised when in non-test environment without Redis URL."""
63- config = AppConfig (ENVIRONMENT = "production" , DRAMATIQ = DramatiqConfig (REDIS_URL = None )) # Mock config
64- with pytest .raises (RuntimeError , match = "Running a non-test environment without Redis URL set" ):
65- init_dramatiq (config )
66+ config = AppConfig (
67+ ENVIRONMENT = "production" , DRAMATIQ = DramatiqConfig (REDIS_URL = None )
68+ ) # Mock config
69+ with pytest .raises (
70+ RuntimeError , match = "Running a non-test environment without Redis URL set"
71+ ):
72+ init_dramatiq (config )
0 commit comments