diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cad13598f..b9cd017a7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,14 @@ jobs: sudo apt update sudo apt install ffmpeg gobject-introspection libcairo2-dev libgirepository1.0-dev pandoc + - name: Get changed lyrics files + id: lyrics-update + uses: tj-actions/changed-files@v45 + with: + files: | + beetsplug/lyrics.py + test/plugins/test_lyrics.py + - name: Add pytest annotator uses: liskin/gh-problem-matcher-wrap@v3 with: @@ -49,6 +57,8 @@ jobs: - if: ${{ env.IS_MAIN_PYTHON == 'true' }} name: Test with coverage + env: + LYRICS_UPDATED: ${{ steps.lyrics-update.outputs.any_changed }} run: | poetry install --extras=autobpm --extras=lyrics --extras=docs --extras=replaygain --extras=reflink poe docs diff --git a/setup.cfg b/setup.cfg index 8cf0dc3d0..15ca23f65 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,6 +8,7 @@ addopts = -ra --strict-config markers = + on_lyrics_update: mark a test to run only after lyrics source code is updated integration_test: mark a test as an integration test [coverage:run] diff --git a/test/conftest.py b/test/conftest.py index 8b29946ae..95509bdb6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,10 +3,21 @@ import os import pytest -def pytest_runtest_setup(item: pytest.Item): - """Skip integration tests if INTEGRATION_TEST environment variable is not set.""" - if os.environ.get("INTEGRATION_TEST"): - return +def skip_marked_items(items: list[pytest.Item], marker_name: str, reason: str): + for item in (i for i in items if i.get_closest_marker(marker_name)): + test_name = item.nodeid.split("::", 1)[-1] + item.add_marker(pytest.mark.skip(f"{reason}: {test_name}")) - if next(item.iter_markers(name="integration_test"), None): - pytest.skip(f"INTEGRATION_TEST=1 required: {item.nodeid}") + +def pytest_collection_modifyitems( + config: pytest.Config, items: list[pytest.Item] +): + if not os.environ.get("INTEGRATION_TEST") == "true": + skip_marked_items( + items, "integration_test", "INTEGRATION_TEST=1 required" + ) + + if not os.environ.get("LYRICS_UPDATED") == "true": + skip_marked_items( + items, "on_lyrics_update", "No change in lyrics source code" + ) diff --git a/test/plugins/test_lyrics.py b/test/plugins/test_lyrics.py index b29143873..04b8e667b 100644 --- a/test/plugins/test_lyrics.py +++ b/test/plugins/test_lyrics.py @@ -199,7 +199,7 @@ class LyricsBackendTest(PluginMixin): encoding="utf-8" ) - @pytest.mark.integration_test + @pytest.mark.on_lyrics_update def test_backend_source(self, backend): """Test default backends with a song known to exist in respective databases. @@ -229,7 +229,7 @@ class TestGoogleLyrics(LyricsBackendTest): def file_name(self): return "examplecom/beetssong" - @pytest.mark.integration_test + @pytest.mark.on_lyrics_update @pytest.mark.parametrize( "title, url", [ @@ -325,7 +325,7 @@ class TestGeniusLyrics(LyricsBackendTest): return "genius" @xfail_on_ci("Genius returns 403 FORBIDDEN") - @pytest.mark.integration_test + @pytest.mark.on_lyrics_update def test_backend_source(self, backend): super().test_backend_source(backend)