From b683cb654057d4e878da24234b88c3a95310eb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Sun, 8 Mar 2026 00:53:35 +0000 Subject: [PATCH] Extend requires_import marker with force_ci option Add force_ci kwarg to requires_import pytest marker to allow tests to run unconditionally in CI (GitHub Actions), even if the module is not detected locally. Refactor autobpm test to use this instead of manual env-checking at module level. --- test/conftest.py | 15 ++++++++++++++- test/plugins/test_autobpm.py | 7 +------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index b98486a96..bff811774 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -38,6 +38,16 @@ def pytest_collection_modifyitems( for item in items: if marker := item.get_closest_marker("requires_import"): + force_ci = marker.kwargs.get("force_ci", True) + if ( + force_ci + and os.environ.get("GITHUB_ACTIONS") == "true" + # only apply this to our repository, to allow other projects to + # run tests without installing all dependencies + and os.environ.get("GITHUB_REPOSITORY", "") == "beetbox/beets" + ): + continue + modname = marker.args[0] if not _is_importable(modname): test_name = item.nodeid.split("::", 1)[-1] @@ -59,7 +69,10 @@ def pytest_configure(config: pytest.Config) -> None: ) config.addinivalue_line( "markers", - "requires_import(module): run test only if the specified module is available", + ( + "requires_import(module, force_ci=True): run test only if module" + " is importable (use force_ci=False to allow CI to skip the test too)" + ), ) diff --git a/test/plugins/test_autobpm.py b/test/plugins/test_autobpm.py index 6093d999f..90ba387ce 100644 --- a/test/plugins/test_autobpm.py +++ b/test/plugins/test_autobpm.py @@ -1,13 +1,8 @@ -import importlib.util -import os - import pytest from beets.test.helper import ImportHelper, PluginMixin -github_ci = os.environ.get("GITHUB_ACTIONS") == "true" -if not github_ci and not importlib.util.find_spec("librosa"): - pytest.skip("librosa isn't available", allow_module_level=True) +pytestmark = pytest.mark.requires_import("librosa") class TestAutoBPMPlugin(PluginMixin, ImportHelper):