diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..b4e1cde --- /dev/null +++ b/conftest.py @@ -0,0 +1,15 @@ +# Copyright (C) 2020 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 + +import pytest + +pytest_plugins = ["swh.scheduler.pytest_plugin", "swh.storage.pytest_plugin"] + + +@pytest.fixture(scope="session") +def swh_scheduler_celery_includes(swh_scheduler_celery_includes): + return swh_scheduler_celery_includes + [ + "swh.loader.mercurial.tasks", + ] diff --git a/pytest.ini b/pytest.ini index afa4cf3..3bd0501 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,5 @@ [pytest] +# Drop this when these fixtures aren't imported automatically anymore +addopts = -p no:pytest_swh_scheduler -p no:pytest_swh_storage + norecursedirs = docs diff --git a/requirements-test.txt b/requirements-test.txt index cbe9478..b1d158f 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,5 +1,5 @@ pytest pytest-mock swh.core[http] >= 0.0.61 -swh.scheduler[testing] +swh.scheduler[testing] >= 0.5.0 swh.storage[testing] diff --git a/swh/loader/mercurial/tests/conftest.py b/swh/loader/mercurial/tests/conftest.py index 450634e..22b0736 100644 --- a/swh/loader/mercurial/tests/conftest.py +++ b/swh/loader/mercurial/tests/conftest.py @@ -1,63 +1,53 @@ # Copyright (C) 2019-2020 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 import os import yaml import pytest from typing import Any, Dict -from swh.scheduler.tests.conftest import * # noqa -from swh.storage.tests.conftest import * # noqa - @pytest.fixture def swh_loader_config(swh_storage_backend_config, tmp_path) -> Dict[str, Any]: swh_storage_backend_config["journal_writer"] = {} return { "storage": { "cls": "pipeline", "steps": [ {"cls": "filter"}, { "cls": "buffer", "min_batch_size": { "content": 10000, "content_bytes": 1073741824, "directory": 2500, "revision": 10, "release": 100, }, }, swh_storage_backend_config, ], }, "bundle_filename": "HG20_none_bundle", "cache1_size": 838860800, "cache2_size": 838860800, "clone_timeout_seconds": 2 * 3600, "reduce_effort": False, "save_data": False, "save_data_path": "", "max_content_size": 104857600, "temp_directory": str(tmp_path), } @pytest.fixture def swh_config(swh_loader_config, monkeypatch, tmp_path): conffile = os.path.join(str(tmp_path), "loader.yml") with open(conffile, "w") as f: f.write(yaml.dump(swh_loader_config)) monkeypatch.setenv("SWH_CONFIG_FILENAME", conffile) return conffile - - -@pytest.fixture(scope="session") # expected redefinition -def celery_includes(): - return [ - "swh.loader.mercurial.tasks", - ] diff --git a/swh/loader/mercurial/tests/test_tasks.py b/swh/loader/mercurial/tests/test_tasks.py index e4cfd1b..30ff840 100644 --- a/swh/loader/mercurial/tests/test_tasks.py +++ b/swh/loader/mercurial/tests/test_tasks.py @@ -1,43 +1,43 @@ # 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 -def test_loader(mocker, swh_app, celery_session_worker): +def test_loader(mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker): mock_loader = mocker.patch("swh.loader.mercurial.loader.HgBundle20Loader.load") mock_loader.return_value = {"status": "eventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.mercurial.tasks.LoadMercurial", kwargs={"url": "origin_url", "directory": "/some/repo", "visit_date": "now",}, ) assert res res.wait() assert res.successful() assert res.result == {"status": "eventful"} mock_loader.assert_called_once_with() -def test_archive_loader(mocker, swh_app, celery_session_worker): +def test_archive_loader(mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker): mock_loader = mocker.patch( "swh.loader.mercurial.loader.HgArchiveBundle20Loader.load" ) mock_loader.return_value = {"status": "uneventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.mercurial.tasks.LoadArchiveMercurial", kwargs={ "url": "another_url", "archive_path": "/some/tar.tgz", "visit_date": "now", }, ) assert res res.wait() assert res.successful() assert res.result == {"status": "uneventful"} mock_loader.assert_called_once_with() diff --git a/tox.ini b/tox.ini index 5919ec0..a8e10fd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,35 +1,36 @@ [tox] envlist=black,flake8,mypy,py3 [testenv] extras = testing deps = pytest-cov + swh.scheduler[testing] swh.storage[testing] commands = pytest --cov={envsitepackagesdir}/swh/loader/mercurial \ {envsitepackagesdir}/swh/loader/mercurial \ --cov-branch {posargs} [testenv:black] skip_install = true deps = black commands = {envpython} -m black --check swh [testenv:flake8] skip_install = true deps = flake8 commands = {envpython} -m flake8 [testenv:mypy] extras = testing deps = mypy commands = mypy swh