Skip to content

Commit 8f3f426

Browse files
[3.9] pythongh-130292: Allow for empty simulator list when running iOS testbed (pythonGH-130388) (python#130532)
Adds error handling when there are no pre-existing test simulators. (cherry picked from commit 99088ab) Co-authored-by: Russell Keith-Magee <[email protected]>
1 parent ad3288d commit 8f3f426

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
@@ -83,19 +83,29 @@ async def async_check_output(*args, **kwargs):
8383

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

100110

101111
async def find_device(initial_devices):

0 commit comments

Comments
 (0)