Skip to content

Commit 2519132

Browse files
committed
tests/appium: use requests for fetching APK
Also add more context for the error. Signed-off-by: Jakub Sokołowski <[email protected]>
1 parent c5676ae commit 2519132

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

test/appium/tests/conftest.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import re
33
import signal
4-
import urllib.request
4+
import requests
55
from contextlib import contextmanager
66
from dataclasses import dataclass
77
from datetime import datetime
@@ -195,6 +195,23 @@ def _upload_and_check_response_with_retries(apk_file_path, retries=3):
195195
except (ConnectionError, RemoteDisconnected):
196196
sleep(10)
197197

198+
def _download_apk(url):
199+
# Absolute path adde to handle CI runs.
200+
apk_path = os.path.join(os.path.dirname(__file__), test_suite_data.apk_name)
201+
202+
try:
203+
resp = requests.get(url)
204+
resp.raise_for_status()
205+
except requests.RequestException as err:
206+
print('Failed GET: %s' % url)
207+
print(resp.text)
208+
raise err
209+
210+
with open(apk_path, 'wb') as f:
211+
f.write(resp.content)
212+
213+
return apk_path
214+
198215
def pytest_configure(config):
199216
global option
200217
option = config.option
@@ -249,10 +266,7 @@ def pytest_configure(config):
249266

250267
if config.getoption('env') == 'sauce' and not is_uploaded():
251268
apk_src = config.getoption('apk')
252-
if apk_src.startsWith('http'):
253-
# Absolute path adde to handle CI runs.
254-
apk_path = os.path.join(os.path.dirname(__file__), test_suite_data.apk_name)
255-
urllib.request.urlretrieve(apk_src, filename=apk_path)
269+
if apk_src.startswith('http'):
256270
else:
257271
apk_path = apk_src
258272

0 commit comments

Comments
 (0)