diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..78a3608 --- /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.svn.tasks", + ] diff --git a/pytest.ini b/pytest.ini index f0d1fc3..81146c2 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,7 @@ [pytest] +# Drop this when these fixtures aren't imported automatically +addopts = -p no:pytest_swh_scheduler -p no:pytest_swh_storage + norecursedirs = docs markers = fs: execute tests that write to the filesystem diff --git a/swh/loader/svn/tests/conftest.py b/swh/loader/svn/tests/conftest.py index d7f7fb8..0a6b97a 100644 --- a/swh/loader/svn/tests/conftest.py +++ b/swh/loader/svn/tests/conftest.py @@ -1,59 +1,49 @@ # 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 pytest import yaml from typing import Any, Dict -from swh.scheduler.tests.conftest import swh_app # noqa -from swh.storage.tests.conftest import * # noqa - @pytest.fixture def swh_loader_config(swh_storage_backend_config) -> 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, ], }, "check_revision": {"limit": 100, "status": False}, "debug": False, "log_db": "dbname=softwareheritage-log", "save_data": False, "save_data_path": "", "temp_directory": "/tmp", } @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") -def celery_includes(): - return [ - "swh.loader.svn.tasks", - ] diff --git a/swh/loader/svn/tests/test_task.py b/swh/loader/svn/tests/test_task.py index 1b5a1d6..1911e39 100644 --- a/swh/loader/svn/tests/test_task.py +++ b/swh/loader/svn/tests/test_task.py @@ -1,51 +1,55 @@ # Copyright (C) 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_svn_loader(mocker, swh_app, celery_session_worker, swh_config): +def test_svn_loader( + mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker, swh_config +): mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoader.load") mock_loader.return_value = {"status": "eventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.svn.tasks.LoadSvnRepository", kwargs=dict(url="some-technical-url", origin_url="origin-url"), ) assert res res.wait() assert res.successful() assert res.result == {"status": "eventful"} -def test_svn_loader_from_dump(mocker, swh_app, celery_session_worker, swh_config): +def test_svn_loader_from_dump( + mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker, swh_config +): mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromDumpArchive.load") mock_loader.return_value = {"status": "eventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.svn.tasks.MountAndLoadSvnRepository", kwargs=dict(url="some-url", archive_path="some-path"), ) assert res res.wait() assert res.successful() assert res.result == {"status": "eventful"} def test_svn_loader_from_remote_dump( - mocker, swh_app, celery_session_worker, swh_config + mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker, swh_config ): mock_loader = mocker.patch("swh.loader.svn.loader.SvnLoaderFromRemoteDump.load") mock_loader.return_value = {"status": "eventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.svn.tasks.DumpMountAndLoadSvnRepository", kwargs=dict(url="some-remote-dump-url", origin_url="origin-url"), ) assert res res.wait() assert res.successful() assert res.result == {"status": "eventful"} diff --git a/tox.ini b/tox.ini index 103b8c8..5e4ffc3 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] >= 0.5.0 dev: pdbpp commands = pytest --cov={envsitepackagesdir}/swh/loader/svn \ {envsitepackagesdir}/swh/loader/svn \ --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