Skip to content

Commit

Permalink
prefer log.warning() in conda.gateways.repodata (#13108)
Browse files Browse the repository at this point in the history
  • Loading branch information
dholth committed Sep 18, 2023
1 parent ba2a25a commit d328e74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conda/gateways/repodata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def load_state(self):
self.load(state_only=True)
except (FileNotFoundError, json.JSONDecodeError) as e:
if isinstance(e, json.JSONDecodeError):
warnings.warn(f"{e.__class__.__name__} loading {self.cache_path_state}")
log.warning(f"{e.__class__.__name__} loading {self.cache_path_state}")
self.state.clear()
return self.state

Expand Down
19 changes: 16 additions & 3 deletions tests/gateways/test_jlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import datetime
import json
import logging
import time
from pathlib import Path
from socket import socket
Expand All @@ -15,6 +16,7 @@
import requests
import zstandard

import conda.gateways.repodata
from conda.base.context import conda_tests_ctxt_mgmt_def_pol, context, reset_context
from conda.common.io import env_vars
from conda.core.subdir_data import SubdirData
Expand Down Expand Up @@ -306,6 +308,7 @@ def test_repodata_state(
def test_repodata_info_jsondecodeerror(
package_server: socket,
use_jlap: bool,
monkeypatch,
):
"""Test that cache metadata file works correctly."""
host, port = package_server.getsockname()
Expand Down Expand Up @@ -346,9 +349,19 @@ def test_repodata_info_jsondecodeerror(
SubdirData.clear_cached_local_channel_data(exclude_file=False)
sd2 = SubdirData(channel=test_channel)

# warnings.warn(f"{e.__class__.__name__} loading {self.cache_path_state}")
with pytest.warns(UserWarning, match=" loading "):
sd2.load()
# caplog fixture was able to capture urllib3 logs but not conda's. Could
# be due to setting propagate=False on conda's root loggers. Instead,
# mock warning() to save messages.
records = []

def warning(*args, **kwargs):
records.append(args)

monkeypatch.setattr(conda.gateways.repodata.log, "warning", warning)

sd2.load()

assert any(record[0].startswith("JSONDecodeError") for record in records)


@pytest.mark.parametrize("use_jlap", ["jlap", "jlapopotamus", "jlap,another", ""])
Expand Down

0 comments on commit d328e74

Please sign in to comment.