@@ -16,8 +16,6 @@ def __init__(self, client, task_list: str, identity: str, **options):
1616 super ().__init__ (client , task_list , identity , ** options )
1717 self ._handle_task_implementation_called = False
1818 self ._handle_task_failure_called = False
19- self ._propagate_context_called = False
20- self ._unset_current_context_called = False
2119 self ._last_task : str = ""
2220 self ._last_error : Exception | None = None
2321
@@ -33,15 +31,6 @@ async def handle_task_failure(self, task: str, error: Exception) -> None:
3331 self ._handle_task_failure_called = True
3432 self ._last_task = task
3533 self ._last_error = error
36-
37- async def _propagate_context (self , task : str ) -> None :
38- """Test implementation of context propagation."""
39- self ._propagate_context_called = True
40- self ._last_task = task
41-
42- async def _unset_current_context (self ) -> None :
43- """Test implementation of context cleanup."""
44- self ._unset_current_context_called = True
4534
4635
4736class TestBaseTaskHandler :
@@ -71,10 +60,8 @@ async def test_handle_task_success(self):
7160
7261 await handler .handle_task ("test_task" )
7362
74- # Verify all methods were called in correct order
75- assert handler ._propagate_context_called
63+ # Verify implementation was called
7664 assert handler ._handle_task_implementation_called
77- assert handler ._unset_current_context_called
7865 assert not handler ._handle_task_failure_called
7966 assert handler ._last_task == "test_task"
8067 assert handler ._last_error is None
@@ -88,72 +75,12 @@ async def test_handle_task_failure(self):
8875 await handler .handle_task ("raise_error" )
8976
9077 # Verify error handling was called
91- assert handler ._propagate_context_called
9278 assert handler ._handle_task_implementation_called
9379 assert handler ._handle_task_failure_called
94- assert handler ._unset_current_context_called
9580 assert handler ._last_task == "raise_error"
9681 assert isinstance (handler ._last_error , ValueError )
9782 assert str (handler ._last_error ) == "Test error"
9883
99- @pytest .mark .asyncio
100- async def test_handle_task_with_context_propagation_error (self ):
101- """Test task handling when context propagation fails."""
102- client = Mock ()
103- handler = ConcreteTaskHandler (client , "test_task_list" , "test_identity" )
104-
105- # Override _propagate_context to raise an error
106- async def failing_propagate_context (task ):
107- raise RuntimeError ("Context propagation failed" )
108-
109- # Use setattr to avoid mypy error about method assignment
110- setattr (handler , '_propagate_context' , failing_propagate_context )
111-
112- await handler .handle_task ("test_task" )
113-
114- # Verify error handling was called
115- assert handler ._handle_task_failure_called
116- assert handler ._unset_current_context_called
117- assert isinstance (handler ._last_error , RuntimeError )
118- assert str (handler ._last_error ) == "Context propagation failed"
119-
120- @pytest .mark .asyncio
121- async def test_handle_task_with_cleanup_error (self ):
122- """Test task handling when cleanup fails."""
123- client = Mock ()
124- handler = ConcreteTaskHandler (client , "test_task_list" , "test_identity" )
125-
126- # Override _unset_current_context to raise an error
127- async def failing_unset_context ():
128- raise RuntimeError ("Cleanup failed" )
129-
130- # Use setattr to avoid mypy error about method assignment
131- setattr (handler , '_unset_current_context' , failing_unset_context )
132-
133- # Cleanup errors in finally block will propagate
134- with pytest .raises (RuntimeError , match = "Cleanup failed" ):
135- await handler .handle_task ("test_task" )
136-
137- @pytest .mark .asyncio
138- async def test_handle_task_with_implementation_and_cleanup_errors (self ):
139- """Test task handling when both implementation and cleanup fail."""
140- client = Mock ()
141- handler = ConcreteTaskHandler (client , "test_task_list" , "test_identity" )
142-
143- # Override _unset_current_context to raise an error
144- async def failing_unset_context ():
145- raise RuntimeError ("Cleanup failed" )
146-
147- # Use setattr to avoid mypy error about method assignment
148- setattr (handler , '_unset_current_context' , failing_unset_context )
149-
150- # The implementation error should be handled, but cleanup error will propagate
151- with pytest .raises (RuntimeError , match = "Cleanup failed" ):
152- await handler .handle_task ("raise_error" )
153-
154- # Verify the implementation error was handled before cleanup error
155- assert handler ._handle_task_failure_called
156- assert isinstance (handler ._last_error , ValueError )
15784
15885 @pytest .mark .asyncio
15986 async def test_abstract_methods_not_implemented (self ):
@@ -175,17 +102,6 @@ async def handle_task_failure(self, task: str, error: Exception) -> None:
175102 with pytest .raises (NotImplementedError ):
176103 await handler .handle_task_failure ("test" , Exception ("test" ))
177104
178- @pytest .mark .asyncio
179- async def test_default_context_methods (self ):
180- """Test default implementations of context methods."""
181- client = Mock ()
182- handler = ConcreteTaskHandler (client , "test_task_list" , "test_identity" )
183-
184- # Test default _propagate_context (should not raise)
185- await handler ._propagate_context ("test_task" )
186-
187- # Test default _unset_current_context (should not raise)
188- await handler ._unset_current_context ()
189105
190106 @pytest .mark .asyncio
191107 async def test_generic_type_parameter (self ):
0 commit comments