Skip to content

Commit 09b2294

Browse files
committed
Refactor test_query
And rewrite test_query.py
1 parent 2c6f314 commit 09b2294

File tree

3 files changed

+376
-781
lines changed

3 files changed

+376
-781
lines changed

beets/test/_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
HAVE_HARDLINK = sys.platform != "win32"
6464

6565

66-
def item(lib=None):
67-
i = beets.library.Item(
66+
def item(lib=None, **kwargs):
67+
defaults = dict(
6868
title="the title",
6969
artist="the artist",
7070
albumartist="the album artist",
@@ -99,6 +99,7 @@ def item(lib=None):
9999
album_id=None,
100100
mtime=12345,
101101
)
102+
i = beets.library.Item(**{**defaults, **kwargs})
102103
if lib:
103104
lib.add(i)
104105
return i

test/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import inspect
12
import os
23

34
import pytest
45

6+
from beets.dbcore.query import Query
7+
58

69
def skip_marked_items(items: list[pytest.Item], marker_name: str, reason: str):
710
for item in (i for i in items if i.get_closest_marker(marker_name)):
@@ -21,3 +24,20 @@ def pytest_collection_modifyitems(
2124
skip_marked_items(
2225
items, "on_lyrics_update", "No change in lyrics source code"
2326
)
27+
28+
29+
def pytest_make_parametrize_id(config, val, argname):
30+
"""Generate readable test identifiers for pytest parametrized tests.
31+
32+
Provides custom string representations for:
33+
- Query classes/instances: use class name
34+
- Lambda functions: show abbreviated source
35+
- Other values: use standard repr()
36+
"""
37+
if inspect.isclass(val) and issubclass(val, Query):
38+
return val.__name__
39+
40+
if inspect.isfunction(val) and val.__name__ == "<lambda>":
41+
return inspect.getsource(val).split("lambda")[-1][:30]
42+
43+
return repr(val)

0 commit comments

Comments
 (0)