"""把存储契约接到库自带的两个实现上。 同一套用例在两种形态上各跑一遍——一个逐行追加进本地文件,一个只留在进程内存里。一条其实 只在其中一种形态下成立的断言在这里当场红;同一条断言写进某一个实现自己的单元测试里,另一个 实现漏掉它不会有任何东西发现。这正是 `research-wiki/design/0014-contract-suite-distribution.md` 决策一把接法从「覆盖同名 fixture」换成「继承基类」换来的:一份契约同时验多个实现。 `contract` 这个标记打在本文件上,不打在套件里。套件随包发到下游,而一个下游开着 `--strict-markers` 又没注册这个 marker 的话,炸掉的是整份文件的收集(决策二第五条)。 """ from pathlib import Path import pytest from polyloop.stores import JsonlRunStore, VolatileRunStore from polyloop.testing import RunStoreContract pytestmark = pytest.mark.contract class TestJsonlRunStore(RunStoreContract): """逐行追加进本地文件的那个实现。""" @pytest.fixture def store(self, tmp_path: Path) -> JsonlRunStore: """`tmp_path` 每条用例一个新目录,套件要的「每次返回一个空存储」自动成立。""" return JsonlRunStore(directory=tmp_path) class TestVolatileRunStore(RunStoreContract): """只留在进程内存里的那个实现。""" @pytest.fixture def store(self) -> VolatileRunStore: return VolatileRunStore()