D10: изолировать ФС в тестах — tmp_path + monkeypatch.chdir
- tests/conftest.py: автофикстура `isolated_cwd` переводит CWD во временный каталог на время каждого теста; добавлена session-фикстура `repo_root` - tests/test_cli.py: удалён `_cleanup()` (он удалял отслеживаемый git файл data/model.json) и импорт MODEL_PATH — 13 вызовов - +2 регрессионных теста: CLI пишет модель в tmp, а отслеживаемый data/model.json в дереве репозитория остаётся байт-в-байт прежним Проверено: `python -m pytest -q` больше не модифицирует data/model.json.
This commit is contained in:
1 parent
b15533f275
commit
bf764723e4
2 files changed
+42
-19
No files matched your search
@@ -1,3 +1,4 @@
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
@@ -14,6 +15,26 @@ from domain import (
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def repo_root() -> Path:
|
||||
"""Корень репозитория (для проверок, что тесты не пишут в дерево)."""
|
||||
return Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def isolated_cwd(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
||||
"""Изоляция ФС: тесты не пишут в рабочее дерево репозитория.
|
||||
|
||||
CLI работает с относительными путями (`data/model.json`, `exports/...`),
|
||||
поэтому достаточно перевести CWD во временный каталог — любой файл,
|
||||
созданный командой, окажется в tmp_path, а не в дереве репозитория.
|
||||
До D10 тесты писали в `./data/model.json` и `_cleanup()` удалял
|
||||
отслеживаемый git файл.
|
||||
"""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
return tmp_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_model() -> FinancialModel:
|
||||
acc_id = uuid4()
|
||||
|
||||
Reference in new issue
Block a user