@@ -84,6 +84,13 @@ def successful_function(x, y):
8484 def test_scoped_decorator_exception (self , mock_capture ):
8585 test_exception = ValueError ("Test exception" )
8686
87+ def check_context_on_capture (exception , ** kwargs ):
88+ # Assert tags are available when capture_exception is called
89+ current_tags = get_tags ()
90+ self .assertEqual (current_tags .get ("important_context" ), "value" )
91+
92+ mock_capture .side_effect = check_context_on_capture
93+
8794 @scoped
8895 def failing_function ():
8996 tag ("important_context" , "value" )
@@ -93,15 +100,8 @@ def failing_function():
93100 with self .assertRaises (ValueError ):
94101 failing_function ()
95102
96- # Exception should be captured with context
97- mock_capture .assert_called_once ()
98- args , kwargs = mock_capture .call_args
99-
100- # Check that the exception was passed
101- self .assertEqual (args [0 ], test_exception )
102-
103- # Check that the context was included in properties
104- self .assertEqual (kwargs .get ("properties" , {}).get ("important_context" ), "value" )
103+ # Verify capture_exception was called
104+ mock_capture .assert_called_once_with (test_exception )
105105
106106 # Context should be cleared after function execution
107107 self .assertEqual (get_tags (), {})
@@ -110,6 +110,13 @@ def failing_function():
110110 def test_new_context_exception_handling (self , mock_capture ):
111111 test_exception = RuntimeError ("Context exception" )
112112
113+ def check_context_on_capture (exception , ** kwargs ):
114+ # Assert inner context tags are available when capture_exception is called
115+ current_tags = get_tags ()
116+ self .assertEqual (current_tags .get ("inner_context" ), "inner_value" )
117+
118+ mock_capture .side_effect = check_context_on_capture
119+
113120 # Set up outer context
114121 tag ("outer_context" , "outer_value" )
115122
@@ -120,15 +127,8 @@ def test_new_context_exception_handling(self, mock_capture):
120127 except RuntimeError :
121128 pass # Expected exception
122129
123- # Exception should be captured with inner context
124- mock_capture .assert_called_once ()
125- args , kwargs = mock_capture .call_args
126-
127- # Check that the exception was passed
128- self .assertEqual (args [0 ], test_exception )
129-
130- # Check that the inner context was included in properties
131- self .assertEqual (kwargs .get ("properties" , {}).get ("inner_context" ), "inner_value" )
130+ # Verify capture_exception was called
131+ mock_capture .assert_called_once_with (test_exception )
132132
133133 # Outer context should still be intact
134- self .assertEqual (get_tags ()["outer_context" ], "outer_value" )
134+ self .assertEqual (get_tags ()["outer_context" ], "outer_value" )
0 commit comments