From 45a1b7c7f1ea043f6b0e9d9e0debe94f3da5685b Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 2 Feb 2019 13:40:17 +0200 Subject: [PATCH 1/5] Test in random order to prevent collisions --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index a84fb2a..c06e586 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,7 @@ deps = mock ipdb pytest-cov + pytest-random-order flaky commands = pytest -v -s -W all --cov pylast --cov-report term-missing {posargs} From 850d746b60019cab032249fa5014d845978211d5 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 2 Feb 2019 13:54:18 +0200 Subject: [PATCH 2/5] Test in random order to prevent collisions --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index c06e586..9e62b74 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ deps = pytest-cov pytest-random-order flaky -commands = pytest -v -s -W all --cov pylast --cov-report term-missing {posargs} +commands = pytest -v -s -W all --cov pylast --cov-report term-missing --random-order {posargs} [testenv:venv] deps = ipdb From cfb81348723a44310d3f0c0fd8585bb65ba46792 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 2 Feb 2019 14:15:31 +0200 Subject: [PATCH 3/5] Only run test_scrobble on a single Python version to avoid collisions --- tests/test_network.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_network.py b/tests/test_network.py index 3ce4951..ebe90ea 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -2,6 +2,7 @@ """ Integration (not unit) tests for pylast.py """ +import sys import time import unittest @@ -11,6 +12,9 @@ from .test_pylast import TestPyLastWithLastFm class TestPyLastNetwork(TestPyLastWithLastFm): + @unittest.skipUnless( + sys.version_info[:2] == (3, 7), "Only run on Python 3.7 to avoid collisions" + ) def test_scrobble(self): # Arrange artist = "test artist" From d4fe9e5b36f8e8bd9d2f04407b735086c5dc59fa Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 3 Feb 2019 12:42:50 +0200 Subject: [PATCH 4/5] Add a delay to allow Last.fm to update scrobbles --- tests/test_network.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_network.py b/tests/test_network.py index ebe90ea..33c349e 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -26,6 +26,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm): self.network.scrobble(artist=artist, title=title, timestamp=timestamp) # Assert + time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later? # limit=2 to ignore now-playing: last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0] self.assertEqual(str(last_scrobble.track.artist).lower(), artist) From 4eec2e763dd9dafeaca968dd7570de43117c76ce Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 3 Feb 2019 12:51:44 +0200 Subject: [PATCH 5/5] Only run test_love on a single Python version to avoid collisions --- tests/test_network.py | 9 +++------ tests/test_pylast.py | 4 ++++ tests/test_track.py | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_network.py b/tests/test_network.py index 33c349e..448e535 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -2,19 +2,16 @@ """ Integration (not unit) tests for pylast.py """ -import sys import time import unittest import pylast -from .test_pylast import TestPyLastWithLastFm +from .test_pylast import PY37, TestPyLastWithLastFm class TestPyLastNetwork(TestPyLastWithLastFm): - @unittest.skipUnless( - sys.version_info[:2] == (3, 7), "Only run on Python 3.7 to avoid collisions" - ) + @unittest.skipUnless(PY37, "Only run on Python 3.7 to avoid collisions") def test_scrobble(self): # Arrange artist = "test artist" @@ -24,9 +21,9 @@ class TestPyLastNetwork(TestPyLastWithLastFm): # Act self.network.scrobble(artist=artist, title=title, timestamp=timestamp) + time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later? # Assert - time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later? # limit=2 to ignore now-playing: last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0] self.assertEqual(str(last_scrobble.track.artist).lower(), artist) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index bb88225..b417fb8 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -3,6 +3,7 @@ Integration (not unit) tests for pylast.py """ import os +import sys import time import unittest @@ -12,6 +13,9 @@ from flaky import flaky import pylast +PY37 = sys.version_info[:2] == (3, 7) + + def load_secrets(): secrets_file = "test_pylast.yaml" if os.path.isfile(secrets_file): diff --git a/tests/test_track.py b/tests/test_track.py index b65d6be..bce28db 100755 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -6,10 +6,11 @@ import unittest import pylast -from .test_pylast import TestPyLastWithLastFm +from .test_pylast import PY37, TestPyLastWithLastFm class TestPyLastTrack(TestPyLastWithLastFm): + @unittest.skipUnless(PY37, "Only run on Python 3.7 to avoid collisions") def test_love(self): # Arrange artist = "Test Artist"