Configure integrated lyrics tests to only run on lyrics code changes

This commit is contained in:
Šarūnas Nejus 2024-10-02 20:23:04 +01:00
parent fc49902f3a
commit 35dcfe508a
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
4 changed files with 31 additions and 9 deletions

View file

@ -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

View file

@ -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]

View file

@ -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"
)

View file

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