Skip to content

Commit 35dcfe5

Browse files
committed
Configure integrated lyrics tests to only run on lyrics code changes
1 parent fc49902 commit 35dcfe5

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

.github/workflows/ci.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ jobs:
3535
sudo apt update
3636
sudo apt install ffmpeg gobject-introspection libcairo2-dev libgirepository1.0-dev pandoc
3737
38+
- name: Get changed lyrics files
39+
id: lyrics-update
40+
uses: tj-actions/changed-files@v45
41+
with:
42+
files: |
43+
beetsplug/lyrics.py
44+
test/plugins/test_lyrics.py
45+
3846
- name: Add pytest annotator
3947
uses: liskin/gh-problem-matcher-wrap@v3
4048
with:
@@ -49,6 +57,8 @@ jobs:
4957
5058
- if: ${{ env.IS_MAIN_PYTHON == 'true' }}
5159
name: Test with coverage
60+
env:
61+
LYRICS_UPDATED: ${{ steps.lyrics-update.outputs.any_changed }}
5262
run: |
5363
poetry install --extras=autobpm --extras=lyrics --extras=docs --extras=replaygain --extras=reflink
5464
poe docs

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ addopts =
88
-ra
99
--strict-config
1010
markers =
11+
on_lyrics_update: mark a test to run only after lyrics source code is updated
1112
integration_test: mark a test as an integration test
1213

1314
[coverage:run]

test/conftest.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
import pytest
44

55

6-
def pytest_runtest_setup(item: pytest.Item):
7-
"""Skip integration tests if INTEGRATION_TEST environment variable is not set."""
8-
if os.environ.get("INTEGRATION_TEST"):
9-
return
6+
def skip_marked_items(items: list[pytest.Item], marker_name: str, reason: str):
7+
for item in (i for i in items if i.get_closest_marker(marker_name)):
8+
test_name = item.nodeid.split("::", 1)[-1]
9+
item.add_marker(pytest.mark.skip(f"{reason}: {test_name}"))
1010

11-
if next(item.iter_markers(name="integration_test"), None):
12-
pytest.skip(f"INTEGRATION_TEST=1 required: {item.nodeid}")
11+
12+
def pytest_collection_modifyitems(
13+
config: pytest.Config, items: list[pytest.Item]
14+
):
15+
if not os.environ.get("INTEGRATION_TEST") == "true":
16+
skip_marked_items(
17+
items, "integration_test", "INTEGRATION_TEST=1 required"
18+
)
19+
20+
if not os.environ.get("LYRICS_UPDATED") == "true":
21+
skip_marked_items(
22+
items, "on_lyrics_update", "No change in lyrics source code"
23+
)

test/plugins/test_lyrics.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def lyrics_html(self, lyrics_root_dir, file_name):
199199
encoding="utf-8"
200200
)
201201

202-
@pytest.mark.integration_test
202+
@pytest.mark.on_lyrics_update
203203
def test_backend_source(self, backend):
204204
"""Test default backends with a song known to exist in respective
205205
databases.
@@ -229,7 +229,7 @@ def plugin_config(self):
229229
def file_name(self):
230230
return "examplecom/beetssong"
231231

232-
@pytest.mark.integration_test
232+
@pytest.mark.on_lyrics_update
233233
@pytest.mark.parametrize(
234234
"title, url",
235235
[
@@ -325,7 +325,7 @@ def backend_name(self):
325325
return "genius"
326326

327327
@xfail_on_ci("Genius returns 403 FORBIDDEN")
328-
@pytest.mark.integration_test
328+
@pytest.mark.on_lyrics_update
329329
def test_backend_source(self, backend):
330330
super().test_backend_source(backend)
331331

0 commit comments

Comments
 (0)