Skip to content

Commit

Permalink
Add pytest-vcr-delete-on-fail
Browse files Browse the repository at this point in the history
To smooth out cassette regeneration workflow -- am constantly getting
HTTP 401/429 responses, which is masking the cause of test failures.
  • Loading branch information
hseg committed Oct 14, 2024
1 parent 8d8517e commit 8871741
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 1 deletion.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ mkdocs-section-index = "^0.3.5"
vcrpy = "^6.0.2"
pytest-recording = "^0.13.1"
pytest-freezegun = "^0.4.2"
pytest-vcr-delete-on-fail = {version = "^2.0.1", python = "^3.8.1"}

[tool.poetry.scripts]
spotdl = "spotdl:console_entry_point"
Expand Down
2 changes: 2 additions & 0 deletions tests/console/test_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_show_version(capsys, monkeypatch, argument):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_download_song(capsys, monkeypatch, last_vcr_recording_time, tmpdir):
"""
This test checks if the song is downloaded correctly
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_download_song(capsys, monkeypatch, last_vcr_recording_time, tmpdir):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_preload_song(capsys, monkeypatch, last_vcr_recording_time, tmpdir):
"""
This test checks if the song is preloaded correctly.
Expand Down
2 changes: 2 additions & 0 deletions tests/providers/audio/test_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_yt_search():
provider = YouTube()

Expand Down Expand Up @@ -43,6 +44,7 @@ def test_yt_search():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_yt_get_results():
provider = YouTube()

Expand Down
2 changes: 2 additions & 0 deletions tests/providers/audio/test_ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_ytm_search():
provider = YouTubeMusic()

Expand Down Expand Up @@ -43,6 +44,7 @@ def test_ytm_search():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_ytm_get_results():
provider = YouTubeMusic()

Expand Down
1 change: 1 addition & 0 deletions tests/providers/lyrics/test_azlyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


# @pytest.mark.vcr()
# @pytest.mark.vcr_delete_on_fail
# def test_get_azlyrics_lyrics():
# azlyrics = AzLyrics()

Expand Down
1 change: 1 addition & 0 deletions tests/providers/lyrics/test_genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


# @pytest.mark.vcr()
# @pytest.mark.vcr_delete_on_fail
# def test_get_genius_lyrics():
# genius = Genius()

Expand Down
1 change: 1 addition & 0 deletions tests/providers/lyrics/test_musixmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


# @pytest.mark.vcr()
# @pytest.mark.vcr_delete_on_fail
# def test_get_musixmatch_lyrics():
# musixmatch = MusixMatch()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setup(tmp_path, monkeypatch):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_get_urls(monkeypatch, last_vcr_recording_time):
"""
Tests if spotdl can be initialized correctly.
Expand Down Expand Up @@ -50,6 +51,7 @@ def test_get_urls(monkeypatch, last_vcr_recording_time):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_download(setup, monkeypatch, tmpdir):
"""
Tests if spotdl can be initialized correctly.
Expand Down
1 change: 1 addition & 0 deletions tests/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
],
)
@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_ytmusic_matching(monkeypatch, query, expected, capsys):
monkeypatch.setattr(SpotifyClient, "init", new_initialize)

Expand Down
3 changes: 3 additions & 0 deletions tests/types/test_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_album_wrong_init():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_album_from_url():
"""
Test if Album class can be initialized from url.
Expand All @@ -38,6 +39,7 @@ def test_album_from_url():


# @pytest.mark.vcr()
# @pytest.mark.vcr_delete_on_fail
# def test_album_from_string():
# """
# Test if Album class can be initialized from string.
Expand All @@ -52,6 +54,7 @@ def test_album_from_url():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_album_length():
"""
Tests if Album.length works correctly.
Expand Down
2 changes: 2 additions & 0 deletions tests/types/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_artist_wrong_init():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_artist_from_url():
"""
Test if Artist class can be initialized from url.
Expand All @@ -56,6 +57,7 @@ def test_artist_from_url():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_artist_from_string():
"""
Test if Artist class can be initialized from string.
Expand Down
3 changes: 3 additions & 0 deletions tests/types/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_playlist_wrong_initget_results():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_playlist_from_url():
"""
Tests if Playlist.from_url() works correctly.
Expand All @@ -58,6 +59,7 @@ def test_playlist_from_url():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_playlist_from_string():
"""
Test if Playlist class can be initialized from string.
Expand All @@ -71,6 +73,7 @@ def test_playlist_from_string():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_playlist_length():
"""
Tests if Playlist.length works correctly.
Expand Down
2 changes: 2 additions & 0 deletions tests/types/test_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_song_wrong_init():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_song_from_url():
"""
Tests if Song.from_url() works correctly.
Expand Down Expand Up @@ -109,6 +110,7 @@ def test_song_from_url():


# @pytest.mark.vcr()
# @pytest.mark.vcr_delete_on_fail
# def test_song_from_search_term():
# """
# Tests if Song.from_search_term() works correctly.
Expand Down
1 change: 1 addition & 0 deletions tests/utils/test_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_download_ffmpeg(monkeypatch, tmpdir):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_convert(tmpdir, monkeypatch, last_vcr_recording_time):
"""
Test convert function.
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_get_status():
status = get_status("master", "dev", "spotdl/spotify-downloader")

assert None not in status


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_get_status_fail():
with pytest.raises(RuntimeError):
get_status("master", "dev", "spotdl/spotify-downloader-fail")


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_check_for_updates(monkeypatch):
monkeypatch.setattr(_version, "__version__", "3.9.4")
message = check_for_updates("spotdl/spotify-downloader")
Expand All @@ -32,20 +35,23 @@ def test_check_for_updates(monkeypatch):


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_check_for_updates_fail(monkeypatch):
monkeypatch.setattr(_version, "__version__", "3.9.4")
with pytest.raises(RuntimeError):
check_for_updates("spotdl/spotify-downloader-fail")


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_create_github_url():
url = create_github_url(WEB_APP_URL)

assert url == "https://api.github.com/repos/spotdl/web-ui/contents/dist?ref=master"


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_download_github_dir(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
download_github_dir(WEB_APP_URL, False)
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/test_m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_create_m3u_content():
playlist = Playlist.from_url(PLAYLIST)
content = create_m3u_content(
Expand All @@ -19,6 +20,7 @@ def test_create_m3u_content():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_create_m3u_file(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
playlist = Playlist.from_url(PLAYLIST)
Expand Down
1 change: 1 addition & 0 deletions tests/utils/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
)
@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_embed_metadata(tmpdir, monkeypatch, last_vcr_recording_time,
output_format):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_song():
songs = parse_query(SONG)

Expand All @@ -28,6 +29,7 @@ def test_parse_song():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_album():
songs = parse_query(ALBUM)

Expand All @@ -36,6 +38,7 @@ def test_parse_album():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_yt_link():
songs = parse_query(YT)

Expand All @@ -45,33 +48,38 @@ def test_parse_yt_link():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_artist():
songs = parse_query(ARTIST)

assert len(songs) > 1


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_album_search():
songs = parse_query(ALBUM_SEARCH)

assert len(songs) > 1


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_saved():
with pytest.raises(SavedError):
parse_query(SAVED)


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_parse_query():
songs = parse_query(QUERY)

assert len(songs) > 1


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_get_search_results():
results = get_search_results("test")
assert len(results) > 1
Expand All @@ -87,6 +95,7 @@ def test_create_empty_song():


@pytest.mark.vcr()
@pytest.mark.vcr_delete_on_fail
def test_get_simple_songs():
songs = get_simple_songs(QUERY)
assert len(songs) > 1

0 comments on commit 8871741

Please sign in to comment.