From aa2dc9005f356b707bc5854848afd23fda0f4f5a Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Tue, 18 Nov 2025 23:00:42 +0300 Subject: [PATCH] Catch ValueError when setting gst required version pytest.importskip is used to catch the case when beetsplug.bpd cannot be imported. On macOS, the gi module was able to be imported, but when trying to specify `gi.require_version`, a ValueError is raised about Gst being unavailable. pytest does not catch this ValueError during importskip as it is not an ImportError, and thus the test suite errors during the test collection phase. With this change, we catch the ValueError, and re-raise it as an ImportError and pytest gracefully skips those tests. --- beetsplug/bpd/gstplayer.py | 11 ++++++++++- docs/changelog.rst | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/beetsplug/bpd/gstplayer.py b/beetsplug/bpd/gstplayer.py index fa23f2b0e..f356b3066 100644 --- a/beetsplug/bpd/gstplayer.py +++ b/beetsplug/bpd/gstplayer.py @@ -27,7 +27,16 @@ import gi from beets import ui -gi.require_version("Gst", "1.0") +try: + gi.require_version("Gst", "1.0") +except ValueError as e: + # on some scenarios, gi may be importable, but we get a ValueError when + # trying to specify the required version. This is problematic in the test + # suite where test_bpd.py has a call to + # pytest.importorskip("beetsplug.bpd"). Re-raising as an ImportError + # makes it so the test collector functions as inteded. + raise ImportError from e + from gi.repository import GLib, Gst # noqa: E402 Gst.init(None) diff --git a/docs/changelog.rst b/docs/changelog.rst index c5a0dab53..2f618103f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -66,6 +66,8 @@ Other changes: - Refactored the ``beets/ui/commands.py`` monolithic file (2000+ lines) into multiple modules within the ``beets/ui/commands`` directory for better maintainability. +- :doc:`plugins/bpd`: Raise ImportError instead of ValueError when GStreamer is + unavailable, enabling ``importorskip`` usage in pytest setup. 2.5.1 (October 14, 2025) ------------------------