From 5ceb7c221590403f491836b67dc5bfff8c4ff92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 15 Nov 2023 14:02:05 +0100 Subject: [PATCH] tests/appium: use requests for fetching APK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add more context for the error. Signed-off-by: Jakub SokoĊ‚owski --- test/appium/tests/conftest.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index c288cfc95a..23598023da 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -1,7 +1,7 @@ import os import re import signal -import urllib.request +import requests from contextlib import contextmanager from dataclasses import dataclass from datetime import datetime @@ -195,6 +195,23 @@ def _upload_and_check_response_with_retries(apk_file_path, retries=3): except (ConnectionError, RemoteDisconnected): sleep(10) +def _download_apk(url): + # Absolute path adde to handle CI runs. + apk_path = os.path.join(os.path.dirname(__file__), test_suite_data.apk_name) + + print('Downloading: %s' % url) + try: + resp = requests.get(url) + resp.raise_for_status() + except requests.RequestException as err: + print(resp.text) + raise err + + with open(apk_path, 'wb') as f: + f.write(resp.content) + + return apk_path + def pytest_configure(config): global option option = config.option @@ -249,15 +266,13 @@ def pytest_configure(config): if config.getoption('env') == 'sauce' and not is_uploaded(): apk_src = config.getoption('apk') - if apk_src.startsWith('http'): - # Absolute path adde to handle CI runs. - apk_path = os.path.join(os.path.dirname(__file__), test_suite_data.apk_name) - urllib.request.urlretrieve(apk_src, filename=apk_path) + if apk_src.startswith('http'): + apk_path = _download_apk(apk_src) else: apk_path = apk_src _upload_and_check_response_with_retries(apk_path) - if apk_src.startsWith('http'): + if apk_src.startswith('http'): os.remove(apk_path)