diff --git a/tests/conftest.py b/tests/conftest.py index ef45a883f7b7797facac85b4446574c64b806ebe..a51252ca71e2904e0adbe24dbea89e91c26f97c3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,14 +2,10 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -import os import pathlib -import tempfile import typing -import zipfile import pytest -import tomli_w import torch from torchvision.transforms.functional import to_pil_image @@ -100,55 +96,6 @@ def temporary_basedir(tmp_path_factory): return tmp_path_factory.mktemp("test-cli") -def pytest_sessionstart(session: pytest.Session) -> None: - """Preset the session start to ensure the Montgomery dataset is always available. - - Parameters - ---------- - session - The session to use. - """ - - from mednet.utils.rc import load_rc - - rc = load_rc() - - database_dir = rc.get("datadir.montgomery") - if database_dir is not None: - # if the user downloaded it, use that copy - return - - # else, we must extract the LFS component (we are likely on the CI) - archive = ( - pathlib.Path(__file__).parents[0] / "data" / "lfs" / "test-database.zip" - ) - assert archive.exists(), ( - f"Neither datadir.montgomery is set on the global configuration, " - f"(typically ~/.config/mednet.toml), or it is possible to detect " - f"the presence of {archive}' (did you git submodule init --update " - f"this submodule?)" - ) - - montgomery_tempdir = tempfile.TemporaryDirectory() - rc.setdefault("datadir.montgomery", montgomery_tempdir.name) - - with zipfile.ZipFile(archive) as zf: - zf.extractall(montgomery_tempdir.name) - - config_filename = "mednet.toml" - with open( - os.path.join(montgomery_tempdir.name, config_filename), "wb" - ) as f: - tomli_w.dump(rc.data, f) - f.flush() - - os.environ["XDG_CONFIG_HOME"] = montgomery_tempdir.name - - # stash the newly created temporary directory so we can erase it when the - key = pytest.StashKey[tempfile.TemporaryDirectory]() - session.stash[key] = montgomery_tempdir - - class DatabaseCheckers: """Helpers for database tests."""