36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""All tests use disposable storage, including module-import side effects."""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
# This runs before test collection: abuse builds source metadata at import time.
|
|
_SESSION_DATA = tempfile.TemporaryDirectory(prefix="omni-pytest-")
|
|
os.environ["OMNI_DATA"] = _SESSION_DATA.name
|
|
os.environ["OMNI_DB"] = str(Path(_SESSION_DATA.name) / "collection.sqlite3")
|
|
|
|
from omni import config
|
|
|
|
config.DATA = Path(_SESSION_DATA.name)
|
|
config.DB = config.DATA / "collection.sqlite3"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def sandbox_data(tmp_path, monkeypatch):
|
|
"""Give every test its own database, not only the new panel tests."""
|
|
monkeypatch.setattr(config, "DATA", tmp_path)
|
|
monkeypatch.setattr(config, "DB", tmp_path / "test.sqlite3")
|
|
monkeypatch.setenv("OMNI_DATA", str(tmp_path))
|
|
monkeypatch.setenv("OMNI_DB", str(config.DB))
|
|
from omni import abuse, panel_api
|
|
monkeypatch.setattr(abuse, "DB", config.DB)
|
|
monkeypatch.setattr(panel_api, "WATCH", tmp_path / "watch.json")
|
|
|
|
|
|
def pytest_unconfigure(config):
|
|
_SESSION_DATA.cleanup()
|