-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
38 lines (29 loc) · 1.07 KB
/
Copy pathconftest.py
File metadata and controls
38 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations
import os
import shutil
import sys
import tempfile
from pathlib import Path
from core.runtime_paths import configure_runtime_home
from storage.db import configure_default_db_path
PROJECT_ROOT = Path(__file__).resolve().parent
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
_TEST_RUNTIME_HOME: Path | None = None
def pytest_configure(config) -> None:
del config
global _TEST_RUNTIME_HOME
if _TEST_RUNTIME_HOME is None:
_TEST_RUNTIME_HOME = Path(tempfile.mkdtemp(prefix="nulla_pytest_home_", dir=tempfile.gettempdir())).resolve()
os.environ["NULLA_HOME"] = str(_TEST_RUNTIME_HOME)
configure_runtime_home(_TEST_RUNTIME_HOME)
configure_default_db_path(_TEST_RUNTIME_HOME / "data" / "nulla_web0_v2.db")
def pytest_unconfigure(config) -> None:
del config
global _TEST_RUNTIME_HOME
configure_runtime_home(None)
configure_default_db_path(None)
if _TEST_RUNTIME_HOME is None:
return
shutil.rmtree(_TEST_RUNTIME_HOME, ignore_errors=True)
_TEST_RUNTIME_HOME = None