diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 7a6d77543fde..bdc801fe1172 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1614,8 +1614,9 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default, break if best_font is not None and (_normalize_weight(prop.get_weight()) != _normalize_weight(best_font.weight)): - _log.warning('findfont: Failed to find font weight %s, now using %s.', - prop.get_weight(), best_font.weight) + _log.warning( + 'findfont: Failed to find font weight %s for %s, now using %s.', + prop.get_weight(), best_font.name, best_font.weight) if best_font is None or best_score >= 10.0: if fallback_to_default: diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 61320928e223..9f4065d1746b 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -603,9 +603,11 @@ def test_normalize_weights(): def test_font_match_warning(caplog): - findfont(FontProperties(family=["DejaVu Sans"], weight=750)) + font = 'DejaVu Sans' + findfont(FontProperties(family=[font], weight=750)) + expected = f'findfont: Failed to find font weight 750 for {font}, now using 700.' logs = [rec.message for rec in caplog.records] - assert 'findfont: Failed to find font weight 750, now using 700.' in logs + assert expected in logs def test_mutable_fontproperty_cache_invalidation():