Skip to content

Commit 8db72a8

Browse files
[3.11] pythongh-129248: Filter out the iOS log prefix from testbed runner output. (pythonGH-129252) (python#129283)
Filter out the iOS log prefix from testbed runner output. (cherry picked from commit a580838) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
1 parent 0298df1 commit 8db72a8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The iOS test runner now strips the log prefix from each line output by the
2+
test suite.

iOS/testbed/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import json
44
import plistlib
5+
import re
56
import shutil
67
import subprocess
78
import sys
@@ -13,6 +14,18 @@
1314

1415
DECODE_ARGS = ("UTF-8", "backslashreplace")
1516

17+
# The system log prefixes each line:
18+
# 2025-01-17 16:14:29.090 Df iOSTestbed[23987:1fd393b4] (Python) ...
19+
# 2025-01-17 16:14:29.090 E iOSTestbed[23987:1fd393b4] (Python) ...
20+
21+
LOG_PREFIX_REGEX = re.compile(
22+
r"^\d{4}-\d{2}-\d{2}" # YYYY-MM-DD
23+
r"\s+\d+:\d{2}:\d{2}\.\d+" # HH:MM:SS.sss
24+
r"\s+\w+" # Df/E
25+
r"\s+iOSTestbed\[\d+:\w+\]" # Process/thread ID
26+
r"\s+\(Python\)\s" # Logger name
27+
)
28+
1629

1730
# Work around a bug involving sys.exit and TaskGroups
1831
# (https://github.com/python/cpython/issues/101515).
@@ -132,6 +145,8 @@ async def log_stream_task(initial_devices):
132145
) as process:
133146
suppress_dupes = False
134147
while line := (await process.stdout.readline()).decode(*DECODE_ARGS):
148+
# Strip the prefix from each log line
149+
line = LOG_PREFIX_REGEX.sub("", line)
135150
# The iOS log streamer can sometimes lag; when it does, it outputs
136151
# a warning about messages being dropped... often multiple times.
137152
# Only print the first of these duplicated warnings.

0 commit comments

Comments
 (0)