Skip to content

Commit 86fac4b

Browse files
authored
fix(lastgenre): Reset plugin config in fixtured tests (#6386)
Fixes a bug in the lastgenre plugin, where test state bled into the following fixtures. Each plugin has a view to the global persisted beets.config field. As a result, config variables that aren't explicitly overwritten are persisted in that global config view. This commit exposes the lastgenre default config as a static method and uses that default config to reset the state in between fixture calls. There were 3 tests that depended on `count: 10` being set on previous test fixtures, which I adjusted accordingly. Discovered and discussed in #6317 , see #6317 (comment)
2 parents 31bbd1f + 723b4bb commit 86fac4b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/plugins/test_lastgenre.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ def test_sort_by_depth(self):
203203
assert res == ["ambient", "electronic"]
204204

205205

206+
@pytest.fixture
207+
def config(config):
208+
"""Provide a fresh beets configuration for every test/parameterize call
209+
210+
This is necessary to prevent the following parameterized test to bleed
211+
config test state in between test cases.
212+
"""
213+
return config
214+
215+
206216
@pytest.mark.parametrize(
207217
"config_values, item_genre, mock_genres, expected_result",
208218
[
@@ -232,6 +242,7 @@ def test_sort_by_depth(self):
232242
"whitelist": True,
233243
"canonical": False,
234244
"prefer_specific": False,
245+
"count": 10,
235246
},
236247
["original unknown", "Blues"],
237248
{
@@ -264,6 +275,7 @@ def test_sort_by_depth(self):
264275
"whitelist": True,
265276
"canonical": False,
266277
"prefer_specific": False,
278+
"count": 10,
267279
},
268280
["original unknown", "Blues"],
269281
{
@@ -313,6 +325,7 @@ def test_sort_by_depth(self):
313325
"whitelist": False,
314326
"canonical": False,
315327
"prefer_specific": False,
328+
"count": 10,
316329
},
317330
["unknown genre"],
318331
{
@@ -545,7 +558,9 @@ def test_sort_by_depth(self):
545558
),
546559
],
547560
)
548-
def test_get_genre(config_values, item_genre, mock_genres, expected_result):
561+
def test_get_genre(
562+
config, config_values, item_genre, mock_genres, expected_result
563+
):
549564
"""Test _get_genre with various configurations."""
550565

551566
def mock_fetch_track_genre(self, trackartist, tracktitle):

0 commit comments

Comments
 (0)