diff --git a/spyder/workers/tests/test_update.py b/spyder/workers/tests/test_update.py index a283109739d..d61e3f81bbb 100644 --- a/spyder/workers/tests/test_update.py +++ b/spyder/workers/tests/test_update.py @@ -10,49 +10,46 @@ from spyder.workers.updates import WorkerUpdates -def test_update(qtbot): +@pytest.fixture +def worker(): + return WorkerUpdates(None) + + +def test_update(qtbot, worker): """Test we offer updates for lower versions.""" - worker = WorkerUpdates(None, False, version="1.0.0") + worker.version = "1.0.0" worker.start() assert worker.update_available -def test_no_update(qtbot): +def test_no_update(qtbot, worker): """Test we don't offer updates for very high versions.""" - worker = WorkerUpdates(None, False, version="1000.0.0") - worker.start() - assert not worker.update_available - - -def test_no_update_development(qtbot): - """Test we don't offer updates for development versions.""" - worker = WorkerUpdates(None, False, version="3.3.2.dev0", - releases=['3.3.1']) + worker.version = "1000.0.0" worker.start() assert not worker.update_available -def test_update_pre_to_pre(qtbot): +def test_update_pre_to_pre(qtbot, worker): """Test we offer updates between prereleases.""" - worker = WorkerUpdates(None, False, version="4.0.0a1", - releases=['4.0.0b5']) + worker.version = "4.0.0a1" + worker.releases = ['4.0.0b5'] worker.start() assert worker.update_available -def test_update_pre_to_final(qtbot): +def test_update_pre_to_final(qtbot, worker): """Test we offer updates from prereleases to the final versions.""" - worker = WorkerUpdates(None, False, version="4.0.0b3", - releases=['4.0.0']) + worker.version = "4.0.0b3" + worker.releases = ['4.0.0'] worker.start() assert worker.update_available @pytest.mark.skipif(not is_anaconda(), reason='It only makes sense for Anaconda.') -def test_releases_anaconda(qtbot): +def test_releases_anaconda(qtbot, worker): """Test we don't include spyder-kernels releases in detected releases.""" - worker = WorkerUpdates(None, False, version="3.3.1") + worker.version = "3.3.1" worker.start() assert '0.2.4' not in worker.releases diff --git a/spyder/workers/updates.py b/spyder/workers/updates.py index 5e6a1c45cfd..db88597f532 100644 --- a/spyder/workers/updates.py +++ b/spyder/workers/updates.py @@ -23,7 +23,8 @@ # Local imports from spyder import __version__ -from spyder.config.base import _, is_stable_version, is_conda_based_app +from spyder.config.base import (_, is_stable_version, is_conda_based_app, + running_under_pytest) from spyder.py3compat import is_text_string from spyder.utils.programs import check_version @@ -52,16 +53,12 @@ class WorkerUpdates(QObject): """ sig_ready = Signal() - def __init__(self, parent, version=""): + def __init__(self, parent): QObject.__init__(self) self._parent = parent self.error = None self.releases = [] - - if not version: - self.version = __version__ - else: - self.version = version + self.version = __version__ self.update_available = None self.latest_release = None @@ -111,6 +108,10 @@ def get_releases(self): data = data.decode() data = json.loads(data) + if running_under_pytest() and self.releases: + # If releases set in pytest, don't overwrite + return + if self.update_from_github: self.releases = [item['tag_name'].replace('v', '') for item in data] @@ -129,7 +130,7 @@ def start(self): logger.debug("Starting WorkerUpdates.") self.update_available = False - self.latest_release = __version__ + self.latest_release = self.version self.error = None try: @@ -228,7 +229,7 @@ def _download_installer(self): dir_path, self.latest_release_version) os.makedirs(installer_dir_path, exist_ok=True) for file in os.listdir(dir_path): - if file not in [__version__, self.latest_release_version]: + if file not in [self.version, self.latest_release_version]: remove = osp.join(dir_path, file) os.remove(remove)