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):