8000 [3.13] gh-130292: Allow for empty simulator list when running iOS tes… · python/cpython@90fc611 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90fc611

Browse files
[3.13] gh-130292: Allow for empty simulator list when running iOS testbed (GH-130388) (#130532)
Adds error handling when there are no pre-existing test simulators. (cherry picked from commit 99088ab) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
1 parent 3161f01 commit 90fc611

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The iOS testbed will now run successfully on a machine that has not
2+
previously run Xcode tests (such as CI configurations).

iOS/testbed/__main__.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,29 @@ async def async_check_output(*args, **kwargs):
8282

8383
# Return a list of UDIDs associated with booted simulators
8484
async def list_devices():
85-
# List the testing simulators, in JSON format
86-
raw_json = await async_check_output(
87-
"xcrun", "simctl", "--set", "testing", "list", "-j"
88-
)
89-
json_data = json.loads(raw_json)
90-
91-
# Filter out the booted iOS simulators
92-
return [
93-
simulator["udid"]
94-
for runtime, simulators in json_data["devices"].items()
95-
for simulator in simulators
96-
if runtime.split(".")[-1].startswith("iOS") and simulator["state"] == "Booted"
97-
]
85+
try:
86+
# List the testing simulators, in JSON format
87+
raw_json = await async_check_output(
88+
"xcrun", "simctl", "--set", "testing", "list", "-j"
89+
)
90+
json_data = json.loads(raw_json)
91+
92+
# Filter out the booted iOS simulators
93+
return [
94+
simulator["udid"]
95+
for runtime, simulators in json_data["devices"].items()
96+
for simulator in simulators
97+
if runtime.split(".")[-1].startswith("iOS") and simulator["state"] == "Booted"
98+
]
99+
except subprocess.CalledProcessError as e:
100+
# If there's no ~/Library/Developer/XCTestDevices folder (which is the
101+
# case on fresh installs, and in some CI environments), `simctl list`
102+
# returns error code 1, rather than an empty list. Handle that case,
103+
# but raise all other errors.
104+
if e.returncode == 1:
105+
return []
106+
else:
107+
raise
98108

99109

100110
async def find_device(initial_devices):

0 commit comments

Comments
 (0)
0