Skip to content

Commit 5ceb7c2

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 2043e93 commit 5ceb7c2

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/appium/tests/conftest.py

+21-6
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+
print('Downloading: %s' % url)
203+
try:
204+
resp = requests.get(url)
205+
resp.raise_for_status()
206+
except requests.RequestException as err:
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,15 +266,13 @@ 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'):
270+
apk_path = _download_apk(apk_src)
256271
else:
257272
apk_path = apk_src
258273

259274
_upload_and_check_response_with_retries(apk_path)
260-
if apk_src.startsWith('http'):
275+
if apk_src.startswith('http'):
261276
os.remove(apk_path)
262277

263278

0 commit comments

Comments
 (0)