diff --git a/requirements-test.txt b/requirements-test.txt index 584dbb5..00557c9 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,3 @@ pytest +pytest-mock swh.scheduler[testing] diff --git a/swh/loader/git/tests/test_tasks.py b/swh/loader/git/tests/test_tasks.py index 46a795d..bc79058 100644 --- a/swh/loader/git/tests/test_tasks.py +++ b/swh/loader/git/tests/test_tasks.py @@ -1,51 +1,52 @@ # Copyright (C) 2018-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from unittest.mock import patch - -@patch('swh.loader.git.loader.GitLoader.load') -def test_git_loader(mock_loader, swh_app, celery_session_worker): +def test_git_loader(mocker, swh_app, celery_session_worker): + mock_loader = mocker.patch('swh.loader.git.loader.GitLoader.load') mock_loader.return_value = {'status': 'eventful'} res = swh_app.send_task( 'swh.loader.git.tasks.UpdateGitRepository', ('origin_url',)) assert res res.wait() assert res.successful() assert res.result == {'status': 'eventful'} mock_loader.assert_called_once_with() -@patch('swh.loader.git.from_disk.GitLoaderFromDisk.load') -def test_git_loader_from_disk(mock_loader, swh_app, celery_session_worker): +def test_git_loader_from_disk(mocker, swh_app, celery_session_worker): + mock_loader = mocker.patch( + 'swh.loader.git.from_disk.GitLoaderFromDisk.load') mock_loader.return_value = {'status': 'uneventful'} res = swh_app.send_task( 'swh.loader.git.tasks.LoadDiskGitRepository', ('origin_url2', '/some/repo', '2018-12-10 00:00')) assert res res.wait() assert res.successful() assert res.result == {'status': 'uneventful'} mock_loader.assert_called_once_with() -@patch('swh.loader.git.from_disk.GitLoaderFromArchive.load') -def test_git_loader_from_archive(mock_loader, swh_app, celery_session_worker): +def test_git_loader_from_archive(mocker, swh_app, celery_session_worker): + mock_loader = mocker.patch( + 'swh.loader.git.from_disk.GitLoaderFromArchive.load') + mock_loader.return_value = {'status': 'failed'} res = swh_app.send_task( 'swh.loader.git.tasks.UncompressAndLoadDiskGitRepository', ('origin_url3', '/some/repo', '2017-01-10 00:00')) assert res res.wait() assert res.successful() assert res.result == {'status': 'failed'} mock_loader.assert_called_once_with()