Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/conftest.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | |||||
import yaml | |||||
import pytest | import pytest | ||||
from typing import Any, Dict | |||||
from swh.scheduler.tests.conftest import * # noqa | from swh.scheduler.tests.conftest import * # noqa | ||||
olasd: I understand why this is going on, but instead of generalizing this (somewhat clunky) pattern I… | |||||
Done Inline Actionsright! ardumont: right! | |||||
Done Inline Actions(I took my old approach back from the origin-visit immutable. This time, create dedicated subtask with a dedicated perimeter instead of letting a task opened too long with an almost ever growing perimeter ;) ardumont: T2484
(I took my old approach back from the origin-visit immutable. This time, create… | |||||
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": 10, | |||||
"content_bytes": 100 * 1024 * 1024, | |||||
"directory": 10, | |||||
"revision": 10, | |||||
"release": 10, | |||||
}, | |||||
}, | |||||
swh_storage_backend_config, | |||||
], | |||||
}, | |||||
"max_content_size": 100 * 1024 * 1024, | |||||
"pack_size_bytes": 4 * 1024 * 1024 * 1024, | |||||
"save_data": False, | |||||
} | |||||
@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) | |||||
Done Inline ActionsThat should probably go up in the loader-core now. ardumont: That should probably go up in the loader-core now. | |||||
return conffile | |||||
@pytest.fixture(scope="session") # type: ignore # expected redefinition | @pytest.fixture(scope="session") # type: ignore # expected redefinition | ||||
def celery_includes(): | def celery_includes(): | ||||
return [ | return [ | ||||
"swh.loader.git.tasks", | "swh.loader.git.tasks", | ||||
] | ] |
I understand why this is going on, but instead of generalizing this (somewhat clunky) pattern I think the relevant fixtures should be properly documented and moved to a dedicated pytest plugin in the source modules. I've ended up doing it for swh.scheduler in D3430, it's not too bad.
(No need to do it right now: you can keep this import *, do the refactoring of swh.storage test fixtures in parallel, and drop the import * when that's done. On the release that moves the pytest fixtures, they'll get auto-imported instead of being pulled in by the import *, so the switch over is backwards compatible.)