From e96d62432f9372a2494d21e3b9b58b7c2058da5f Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Fri, 26 Jun 2026 19:56:11 -0700 Subject: [PATCH] test(album-completeness): stop polluting sys.modules (fix flaky suite failure) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the file faked spotipy + config.settings in sys.modules at import time with no teardown. the fake config.settings had no ConfigManager, so depending on collection order it leaked into tests/test_config_save_retry and intermittently failed the full suite. the real modules import fine in the test env (spotipy is installed, config.settings has both ConfigManager + config_manager), so the stubs were pure liability — removed them. album tests still pass (10), the album+config combo that errored now passes (17), 573 repair/ config/canonical tests green. --- tests/test_album_completeness_job.py | 34 ++++------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/tests/test_album_completeness_job.py b/tests/test_album_completeness_job.py index bd0885cd..4cca27fc 100644 --- a/tests/test_album_completeness_job.py +++ b/tests/test_album_completeness_job.py @@ -1,4 +1,3 @@ -import sys import types @@ -10,35 +9,10 @@ class _DummyConfigManager: return "plex" -if "spotipy" not in sys.modules: - spotipy = types.ModuleType("spotipy") - - class _DummySpotify: - def __init__(self, *args, **kwargs): - pass - - oauth2 = types.ModuleType("spotipy.oauth2") - - class _DummyOAuth: - def __init__(self, *args, **kwargs): - pass - - spotipy.Spotify = _DummySpotify - oauth2.SpotifyOAuth = _DummyOAuth - oauth2.SpotifyClientCredentials = _DummyOAuth - spotipy.oauth2 = oauth2 - sys.modules["spotipy"] = spotipy - sys.modules["spotipy.oauth2"] = oauth2 - -if "config.settings" not in sys.modules: - config_pkg = types.ModuleType("config") - settings_mod = types.ModuleType("config.settings") - - settings_mod.config_manager = _DummyConfigManager() - config_pkg.settings = settings_mod - sys.modules["config"] = config_pkg - sys.modules["config.settings"] = settings_mod - +# NOTE: deliberately no sys.modules stubbing of spotipy / config.settings here. Both import +# fine in the test env, and faking them globally (with no teardown) leaked into other files — +# it left a config.settings with no ConfigManager, intermittently breaking +# tests/test_config_save_retry depending on collection order. from core.repair_jobs.album_completeness import AlbumCompletenessJob import core.repair_jobs.album_completeness as album_completeness_module