@@ -1113,37 +1113,37 @@ async def cancel_child(self) -> None:
1113
1113
@pytest .mark .parametrize ("use_execute" , [True , False ])
1114
1114
async def test_workflow_cancel_child_started (client : Client , use_execute : bool ):
1115
1115
async with new_worker (client , CancelChildWorkflow , LongSleepWorkflow ) as worker :
1116
- with pytest .raises (WorkflowFailureError ) as err :
1117
- # Start workflow
1118
- handle = await client .start_workflow (
1119
- CancelChildWorkflow .run ,
1120
- use_execute ,
1121
- id = f"workflow-{ uuid .uuid4 ()} " ,
1122
- task_queue = worker .task_queue ,
1123
- )
1116
+ # Start workflow
1117
+ handle = await client .start_workflow (
1118
+ CancelChildWorkflow .run ,
1119
+ use_execute ,
1120
+ id = f"workflow-{ uuid .uuid4 ()} " ,
1121
+ task_queue = worker .task_queue ,
1122
+ )
1124
1123
1125
- # Wait until child started
1126
- async def child_started () -> bool :
1127
- try :
1128
- return await handle .query (
1129
- CancelChildWorkflow .ready
1130
- ) and await client .get_workflow_handle_for (
1131
- LongSleepWorkflow .run , # type: ignore[arg-type]
1132
- workflow_id = f"{ handle .id } _child" ,
1133
- ).query (LongSleepWorkflow .started )
1134
- except RPCError as err :
1135
- # Ignore not-found or failed precondition because child may
1136
- # not have started yet
1137
- if (
1138
- err .status == RPCStatusCode .NOT_FOUND
1139
- or err .status == RPCStatusCode .FAILED_PRECONDITION
1140
- ):
1141
- return False
1142
- raise
1124
+ # Wait until child started
1125
+ async def child_started () -> bool :
1126
+ try :
1127
+ return await handle .query (
1128
+ CancelChildWorkflow .ready
1129
+ ) and await client .get_workflow_handle_for (
1130
+ LongSleepWorkflow .run , # type: ignore[arg-type]
1131
+ workflow_id = f"{ handle .id } _child" ,
1132
+ ).query (LongSleepWorkflow .started )
1133
+ except RPCError as err :
1134
+ # Ignore not-found or failed precondition because child may
1135
+ # not have started yet
1136
+ if (
1137
+ err .status == RPCStatusCode .NOT_FOUND
1138
+ or err .status == RPCStatusCode .FAILED_PRECONDITION
1139
+ ):
1140
+ return False
1141
+ raise
1143
1142
1144
- await assert_eq_eventually (True , child_started )
1145
- # Send cancel signal and wait on the handle
1146
- await handle .signal (CancelChildWorkflow .cancel_child )
1143
+ await assert_eq_eventually (True , child_started )
1144
+ # Send cancel signal and wait on the handle
1145
+ await handle .signal (CancelChildWorkflow .cancel_child )
1146
+ with pytest .raises (WorkflowFailureError ) as err :
1147
1147
await handle .result ()
1148
1148
assert isinstance (err .value .cause , ChildWorkflowError )
1149
1149
assert isinstance (err .value .cause .cause , CancelledError )
@@ -2374,17 +2374,17 @@ async def test_workflow_already_started(client: Client, env: WorkflowEnvironment
2374
2374
async with new_worker (client , LongSleepWorkflow ) as worker :
2375
2375
id = f"workflow-{ uuid .uuid4 ()} "
2376
2376
# Try to start it twice
2377
+ await client .start_workflow (
2378
+ LongSleepWorkflow .run ,
2379
+ id = id ,
2380
+ task_queue = worker .task_queue ,
2381
+ )
2377
2382
with pytest .raises (WorkflowAlreadyStartedError ):
2378
2383
await client .start_workflow (
2379
2384
LongSleepWorkflow .run ,
2380
2385
id = id ,
2381
2386
task_queue = worker .task_queue ,
2382
2387
)
2383
- await client .start_workflow (
2384
- LongSleepWorkflow .run ,
2385
- id = id ,
2386
- task_queue = worker .task_queue ,
2387
- )
2388
2388
2389
2389
2390
2390
@workflow .defn
@@ -3263,15 +3263,15 @@ async def test_workflow_custom_failure_converter(client: Client):
3263
3263
client = Client (** config )
3264
3264
3265
3265
# Run workflow and confirm error
3266
- with pytest . raises ( WorkflowFailureError ) as err :
3267
- async with new_worker (
3268
- client , CustomErrorWorkflow , activities = [ custom_error_activity ]
3269
- ) as worker :
3270
- handle = await client . start_workflow (
3271
- CustomErrorWorkflow . run ,
3272
- id = f"workflow- { uuid . uuid4 () } " ,
3273
- task_queue = worker . task_queue ,
3274
- )
3266
+ async with new_worker (
3267
+ client , CustomErrorWorkflow , activities = [ custom_error_activity ]
3268
+ ) as worker :
3269
+ handle = await client . start_workflow (
3270
+ CustomErrorWorkflow . run ,
3271
+ id = f"workflow- { uuid . uuid4 () } " ,
3272
+ task_queue = worker . task_queue ,
3273
+ )
3274
+ with pytest . raises ( WorkflowFailureError ) as err :
3275
3275
await handle .result ()
3276
3276
3277
3277
# Check error is as expected
@@ -4606,13 +4606,13 @@ async def test_workflow_timeout_support(client: Client, approach: str):
4606
4606
client , TimeoutSupportWorkflow , activities = [wait_cancel ]
4607
4607
) as worker :
4608
4608
# Run and confirm activity gets cancelled
4609
+ handle = await client .start_workflow (
4610
+ TimeoutSupportWorkflow .run ,
4611
+ approach ,
4612
+ id = f"workflow-{ uuid .uuid4 ()} " ,
4613
+ task_queue = worker .task_queue ,
4614
+ )
4609
4615
with pytest .raises (WorkflowFailureError ) as err :
4610
- handle = await client .start_workflow (
4611
- TimeoutSupportWorkflow .run ,
4612
- approach ,
4613
- id = f"workflow-{ uuid .uuid4 ()} " ,
4614
- task_queue = worker .task_queue ,
4615
- )
4616
4616
await handle .result ()
4617
4617
assert isinstance (err .value .cause , ActivityError )
4618
4618
assert isinstance (err .value .cause .cause , CancelledError )
@@ -4946,8 +4946,8 @@ async def run(self, param: str) -> None:
4946
4946
4947
4947
4948
4948
async def test_workflow_fail_on_bad_input (client : Client ):
4949
- with pytest . raises ( WorkflowFailureError ) as err :
4950
- async with new_worker ( client , FailOnBadInputWorkflow ) as worker :
4949
+ async with new_worker ( client , FailOnBadInputWorkflow ) as worker :
4950
+ with pytest . raises ( WorkflowFailureError ) as err :
4951
4951
await client .execute_workflow (
4952
4952
"FailOnBadInputWorkflow" ,
4953
4953
123 ,
@@ -5484,15 +5484,19 @@ async def _run_workflow_and_get_warning(self) -> bool:
5484
5484
assert update_task
5485
5485
with pytest .raises (RPCError ) as update_err :
5486
5486
await update_task
5487
- assert (
5488
- update_err .value .status == RPCStatusCode .NOT_FOUND
5489
- and "workflow execution already completed"
5490
- in str (update_err .value ).lower ()
5491
- )
5487
+ assert update_err .value .status == RPCStatusCode .NOT_FOUND and (
5488
+ str (update_err .value ).lower ()
5489
+ == "workflow execution already completed"
5490
+ )
5492
5491
5493
5492
with pytest .raises (WorkflowFailureError ) as err :
5494
5493
await handle .result ()
5495
- assert "workflow execution failed" in str (err .value ).lower ()
5494
+ assert isinstance (
5495
+ err .value .cause ,
5496
+ {"cancellation" : CancelledError , "failure" : ApplicationError }[
5497
+ self .workflow_termination_type
5498
+ ],
5499
+ )
5496
5500
5497
5501
unfinished_handler_warning_emitted = any (
5498
5502
issubclass (w .category , self ._unfinished_handler_warning_cls )
0 commit comments