diff --git a/dvc/analytics.py b/dvc/analytics.py index f0bc086d7..624b6c0c2 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -81,12 +81,21 @@ def is_enabled(): def send(report): + """ + Side effect: Removes the report after sending it. + + The report is generated and stored in a temporary file, see: + `collect_and_send_report`. Sending happens on another process, + thus, the need of removing such file afterwards. + """ url = "https://analytics.dvc.org" headers = {"content-type": "application/json"} with open(report, "rb") as fobj: requests.post(url, data=fobj, headers=headers, timeout=5) + os.remove(report) + def scm_in_use(): try: diff --git a/dvc/command/daemon.py b/dvc/command/daemon.py index 68d4b36f6..da9210584 100644 --- a/dvc/command/daemon.py +++ b/dvc/command/daemon.py @@ -1,7 +1,5 @@ from __future__ import unicode_literals -import os - from dvc.command.base import CmdBaseNoRepo from dvc.command.base import fix_subparsers @@ -12,6 +10,7 @@ class CmdDaemonBase(CmdBaseNoRepo): class CmdDaemonUpdater(CmdDaemonBase): def run(self): + import os from dvc.repo import Repo from dvc.updater import Updater @@ -27,10 +26,7 @@ class CmdDaemonAnalytics(CmdDaemonBase): def run(self): from dvc import analytics - report = self.args.target - - analytics.send(report) - os.remove(report) + analytics.send(self.args.target) return 0 diff --git a/tests/func/test_analytics.py b/tests/func/test_analytics.py index df7454965..863b0e329 100644 --- a/tests/func/test_analytics.py +++ b/tests/func/test_analytics.py @@ -5,13 +5,11 @@ from dvc.utils.compat import fspath @mock.patch("dvc.analytics.send") -@mock.patch("os.remove") -def test_daemon_analytics(mock_remove, mock_send, tmp_path): +def test_daemon_analytics(mock_send, tmp_path): report = fspath(tmp_path) assert 0 == main(["daemon", "analytics", report]) mock_send.assert_called_with(report) - mock_remove.assert_called_with(report) @mock.patch("dvc.daemon._spawn")