Skip to content

Commit f79c125

Browse files
authored
Catch ValueError when beetsplug.bpd cannot be imported (#6170)
Catch ValueError when setting gst required version `pytest.importorskip` 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. Fixes #3324
2 parents 88ca0ce + aa2dc90 commit f79c125

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

beetsplug/bpd/gstplayer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727

2828
from beets import ui
2929

30-
gi.require_version("Gst", "1.0")
30+
try:
31+
gi.require_version("Gst", "1.0")
32+
except ValueError as e:
33+
# on some scenarios, gi may be importable, but we get a ValueError when
34+
# trying to specify the required version. This is problematic in the test
35+
# suite where test_bpd.py has a call to
36+
# pytest.importorskip("beetsplug.bpd"). Re-raising as an ImportError
37+
# makes it so the test collector functions as inteded.
38+
raise ImportError from e
39+
3140
from gi.repository import GLib, Gst # noqa: E402
3241

3342
Gst.init(None)

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Other changes:
6666
- Refactored the ``beets/ui/commands.py`` monolithic file (2000+ lines) into
6767
multiple modules within the ``beets/ui/commands`` directory for better
6868
maintainability.
69+
- :doc:`plugins/bpd`: Raise ImportError instead of ValueError when GStreamer is
70+
unavailable, enabling ``importorskip`` usage in pytest setup.
6971

7072
2.5.1 (October 14, 2025)
7173
------------------------

0 commit comments

Comments
 (0)