mirror of
https://github.com/beetbox/beets.git
synced 2026-03-23 13:53:15 +01:00
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.
This commit is contained in:
parent
13ad15b83e
commit
b683cb6540
2 changed files with 15 additions and 7 deletions
|
|
@ -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)"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue