mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
analytics: ignore request.post errors (#3292)
Users have been complaining about dvc analytics errors when they are not connected to the internet.
This commit is contained in:
+4
-1
@@ -76,7 +76,10 @@ def send(report):
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
with open(report, "rb") as fobj:
|
||||
requests.post(url, data=fobj, headers=headers, timeout=5)
|
||||
try:
|
||||
requests.post(url, data=fobj, headers=headers, timeout=5)
|
||||
except requests.exceptions.RequestException:
|
||||
logger.debug("failed to send analytics report", exc_info=True)
|
||||
|
||||
os.remove(report)
|
||||
|
||||
|
||||
@@ -61,16 +61,19 @@ def test_runtime_info(tmp_global_config):
|
||||
|
||||
@mock.patch("requests.post")
|
||||
def test_send(mock_post, tmp_path):
|
||||
import requests
|
||||
|
||||
url = "https://analytics.dvc.org"
|
||||
report = {"name": "dummy report"}
|
||||
fname = str(tmp_path / "report")
|
||||
report_file = tmp_path / "report"
|
||||
|
||||
with open(fname, "w") as fobj:
|
||||
json.dump(report, fobj)
|
||||
report_file.write_text(json.dumps(report))
|
||||
mock_post.side_effect = requests.exceptions.RequestException
|
||||
|
||||
analytics.send(fname)
|
||||
analytics.send(str(report_file))
|
||||
assert mock_post.called
|
||||
assert mock_post.call_args.args[0] == url
|
||||
assert not report_file.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user