diff --git a/dvc/analytics.py b/dvc/analytics.py index 75ce5c58c..e17b6291c 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -119,7 +119,7 @@ def find_or_create_user_id(): try: with Lock(lockfile): try: - user_id = json.load(fname.read_text())["user_id"] + user_id = json.loads(fname.read_text())["user_id"] except (FileNotFoundError, json.JSONDecodeError, AttributeError): user_id = str(uuid.uuid4()) makedirs(fname.parent, exist_ok=True) diff --git a/tests/func/test_analytics.py b/tests/func/test_analytics.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/func/test_analytics.py @@ -0,0 +1 @@ + diff --git a/tests/unit/test_analytics.py b/tests/unit/test_analytics.py index 2fbe134d4..302bff381 100644 --- a/tests/unit/test_analytics.py +++ b/tests/unit/test_analytics.py @@ -1,4 +1,5 @@ import pytest +import mock from dvc import analytics @@ -22,3 +23,13 @@ def test_is_enabled(dvc_repo, config, result, monkeypatch): monkeypatch.delenv("DVC_TEST") assert result == analytics.is_enabled() + + +def test_find_or_create_user_id(tmp_path): + with mock.patch( + "dvc.config.Config.get_global_config_dir", return_value=tmp_path + ): + created = analytics.find_or_create_user_id() + found = analytics.find_or_create_user_id() + + assert created == found