From 5757579e275e61ff4b62a4294c94279300ca2f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 6 Oct 2025 09:01:33 +0100 Subject: [PATCH] Improve visibility of Distance tests failures --- test/autotag/test_distance.py | 17 +++++++---------- test/conftest.py | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/autotag/test_distance.py b/test/autotag/test_distance.py index 8c4478ca9..72922470b 100644 --- a/test/autotag/test_distance.py +++ b/test/autotag/test_distance.py @@ -17,16 +17,15 @@ _p = pytest.param class TestDistance: - @pytest.fixture(scope="class") - def config(self): - return ConfigMixin().config - - @pytest.fixture - def dist(self, config): + @pytest.fixture(autouse=True, scope="class") + def setup_config(self): + config = ConfigMixin().config config["match"]["distance_weights"]["data_source"] = 2.0 config["match"]["distance_weights"]["album"] = 4.0 config["match"]["distance_weights"]["medium"] = 2.0 + @pytest.fixture + def dist(self): return Distance() def test_add(self, dist): @@ -161,10 +160,8 @@ class TestTrackDistance: def test_track_distance(self, info, title, artist, expected_penalty): item = Item(artist=artist, title=title) - assert ( - bool(track_distance(item, info, incl_artist=True)) - == expected_penalty - ) + dist = track_distance(item, info, incl_artist=True) + assert bool(dist) == expected_penalty, dist._penalties class TestAlbumDistance: diff --git a/test/conftest.py b/test/conftest.py index e1350b092..eb46b94b0 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,6 +3,7 @@ import os import pytest +from beets.autotag.distance import Distance from beets.dbcore.query import Query from beets.util import cached_classproperty @@ -44,6 +45,11 @@ def pytest_make_parametrize_id(config, val, argname): return repr(val) +def pytest_assertrepr_compare(op, left, right): + if isinstance(left, Distance) or isinstance(right, Distance): + return [f"Comparing Distance: {float(left)} {op} {float(right)}"] + + @pytest.fixture(autouse=True) def clear_cached_classproperty(): cached_classproperty.cache.clear()