@@ -82,19 +82,29 @@ async def async_check_output(*args, **kwargs):
82
82
83
83
# Return a list of UDIDs associated with booted simulators
84
84
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
98
108
99
109
100
110
async def find_device (initial_devices ):
0 commit comments