File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ def _add_community_link(e):
87
87
elif COMMUNITY not in e .args [0 ]:
88
88
message = e .args [0 ] + COMMUNITY
89
89
e .args = (message ,)
90
+ # Certain exceptions like ClickException have message
91
+ # as their first parameter. In that case args is not
92
+ # accessed while raising the error
93
+ if hasattr (e , "message" ):
94
+ e .message = message
90
95
91
96
return e
92
97
Original file line number Diff line number Diff line change @@ -54,6 +54,23 @@ def crash():
54
54
assert exceptions .get_community_link () in str (excinfo .value )
55
55
56
56
57
+ def test_modify_exceptions_with_message_attribute ():
58
+ class CustomException (Exception ):
59
+ def __init__ (self , message : str ) -> None :
60
+ super ().__init__ (message )
61
+ self .message = message
62
+ self .modify_exception = True
63
+
64
+ @exceptions .modify_exceptions
65
+ def crash ():
66
+ raise CustomException ("some message" )
67
+
68
+ with pytest .raises (CustomException ) as excinfo :
69
+ crash ()
70
+
71
+ assert exceptions .get_community_link () in str (excinfo .value )
72
+
73
+
57
74
def test_modify_exceptions_value_error ():
58
75
@exceptions .modify_exceptions
59
76
def crash ():
You can’t perform that action at this time.
0 commit comments