11import logging
22import os
33import random
4+ from itertools import chain
45from unittest import mock
56
67import pytest
@@ -69,14 +70,13 @@ def test_bad_run_dir(endpoint_uuid, task_uuid, run_dir):
6970 execute_task (task_uuid , b"" , endpoint_uuid , run_dir = None )
7071
7172
72- def test_happy_path (serde , caplog , task_uuid , ez_pack_task , execute_task_runner ):
73+ def test_happy_path (serde , mock_log , task_uuid , ez_pack_task , execute_task_runner ):
7374 out = random .randint (1 , 100_000 )
7475 divisor = random .randint (1 , 100_000 )
7576
7677 task_bytes = ez_pack_task (divide , divisor * out , divisor )
7778
78- with caplog .at_level (logging .DEBUG ):
79- packed_result = execute_task_runner (task_bytes )
79+ packed_result = execute_task_runner (task_bytes )
8080 assert isinstance (packed_result , bytes )
8181
8282 result = messagepack .unpack (packed_result )
@@ -89,7 +89,12 @@ def test_happy_path(serde, caplog, task_uuid, ez_pack_task, execute_task_runner)
8989 assert "endpoint_id" in result .details
9090 assert serde .deserialize (result .data ) == out
9191
92- log_msgs = "\n " .join (r .msg % r .args for r in caplog .records )
92+ log_recs = []
93+ for a , _ in chain (mock_log .info .call_args_list , mock_log .debug .call_args_list ):
94+ fmt , * a = a
95+ log_recs .append (a and fmt % tuple (a ) or fmt )
96+ log_msgs = "\n " .join (log_recs )
97+
9398 assert "Preparing to execute" in log_msgs , "Expect log clue of progress"
9499 assert "Unpacking" in log_msgs , "Expect log clue of progress"
95100 assert "Deserializing function" in log_msgs , "Expect log to clue of progress"
@@ -98,8 +103,8 @@ def test_happy_path(serde, caplog, task_uuid, ez_pack_task, execute_task_runner)
98103 assert "Task function complete" in log_msgs , "Expect log clue of progress"
99104 assert "Execution completed" in log_msgs , "Expect log clue of progress"
100105 assert "Task processing completed in" in log_msgs , "Expect log clue of progress"
101- assert len (caplog . records ) == 7 , "Time to update test?"
102- assert log_msgs .count (str (task_uuid )) == len (caplog . records ), "Expect id prefixed"
106+ assert len (log_recs ) == 7 , "Time to update test?"
107+ assert log_msgs .count (str (task_uuid )) == len (log_recs ), "Expect id always prefixed"
103108
104109
105110def test_sandbox (task_10_2 , execute_task_runner , task_uuid , tmp_path ):
0 commit comments