From 5e226357055ed44147154ad8aacd173f6044b029 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Jun 2020 19:22:33 +0300 Subject: [PATCH] Only test write operations on a single Python version to avoid collision failures --- tests/test_artist.py | 7 ++++++- tests/test_network.py | 5 +++-- tests/test_pylast.py | 2 +- tests/test_track.py | 5 +++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_artist.py b/tests/test_artist.py index 435db955..8250f5bd 100755 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -5,7 +5,7 @@ import pylast import pytest -from .test_pylast import TestPyLastWithLastFm +from .test_pylast import WRITE_TEST, TestPyLastWithLastFm class TestPyLastArtist(TestPyLastWithLastFm): @@ -141,6 +141,7 @@ def test_artist_listener_count(self): assert isinstance(count, int) assert count > 0 + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_tag_artist(self): # Arrange artist = self.network.get_artist("Test Artist") @@ -159,6 +160,7 @@ def test_tag_artist(self): break assert found + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_remove_tag_of_type_text(self): # Arrange tag = "testing" # text @@ -177,6 +179,7 @@ def test_remove_tag_of_type_text(self): break assert not found + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_remove_tag_of_type_tag(self): # Arrange tag = pylast.Tag("testing", self.network) # Tag @@ -195,6 +198,7 @@ def test_remove_tag_of_type_tag(self): break assert not found + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_remove_tags(self): # Arrange tags = ["removetag1", "removetag2"] @@ -218,6 +222,7 @@ def test_remove_tags(self): assert not found1 assert not found2 + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_set_tags(self): # Arrange tags = ["sometag1", "sometag2"] diff --git a/tests/test_network.py b/tests/test_network.py index 8c84760e..bad8c547 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -8,11 +8,11 @@ import pylast import pytest -from .test_pylast import PY37, TestPyLastWithLastFm +from .test_pylast import WRITE_TEST, TestPyLastWithLastFm class TestPyLastNetwork(TestPyLastWithLastFm): - @pytest.mark.skipif(not PY37, reason="Only run on Python 3.7 to avoid collisions") + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_scrobble(self): # Arrange artist = "test artist" @@ -30,6 +30,7 @@ def test_scrobble(self): assert str(last_scrobble.track.artist).lower() == artist assert str(last_scrobble.track.title).lower() == title + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_update_now_playing(self): # Arrange artist = "Test Artist" diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 6b86ce92..83a64adb 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -10,7 +10,7 @@ import pytest from flaky import flaky -PY37 = sys.version_info[:2] == (3, 7) +WRITE_TEST = sys.version_info[:2] == (3, 8) def load_secrets(): diff --git a/tests/test_track.py b/tests/test_track.py index d3f5e6aa..3bfe995d 100755 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -7,10 +7,11 @@ import pylast import pytest -from .test_pylast import PY37, TestPyLastWithLastFm +from .test_pylast import WRITE_TEST, TestPyLastWithLastFm class TestPyLastTrack(TestPyLastWithLastFm): + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_love(self): # Arrange artist = "Test Artist" @@ -26,7 +27,7 @@ def test_love(self): assert str(loved[0].track.artist).lower() == "test artist" assert str(loved[0].track.title).lower() == "test title" - @pytest.mark.skipif(not PY37, reason="Only run on Python 3.7 to avoid collisions") + @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") def test_unlove(self): # Arrange artist = pylast.Artist("Test Artist", self.network)