|
1 | 1 | import os
|
2 | 2 | import re
|
3 | 3 | import signal
|
4 |
| -import urllib.request |
| 4 | +import requests |
5 | 5 | from contextlib import contextmanager
|
6 | 6 | from dataclasses import dataclass
|
7 | 7 | from datetime import datetime
|
@@ -195,6 +195,23 @@ def _upload_and_check_response_with_retries(apk_file_path, retries=3):
|
195 | 195 | except (ConnectionError, RemoteDisconnected):
|
196 | 196 | sleep(10)
|
197 | 197 |
|
| 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 | + |
198 | 215 | def pytest_configure(config):
|
199 | 216 | global option
|
200 | 217 | option = config.option
|
@@ -249,15 +266,13 @@ def pytest_configure(config):
|
249 | 266 |
|
250 | 267 | if config.getoption('env') == 'sauce' and not is_uploaded():
|
251 | 268 | 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) |
256 | 271 | else:
|
257 | 272 | apk_path = apk_src
|
258 | 273 |
|
259 | 274 | _upload_and_check_response_with_retries(apk_path)
|
260 |
| - if apk_src.startsWith('http'): |
| 275 | + if apk_src.startswith('http'): |
261 | 276 | os.remove(apk_path)
|
262 | 277 |
|
263 | 278 |
|
|
0 commit comments