示例工程 29-testing-pytest
29-testing-pytest/01-fixture-scopes/README.md
# 01 · fixture-scopes
**演示**:`@pytest.fixture` 的 `scope` 决定生命周期:`function` 每个测试新建,`module`/`session` 复用;测试里用对象身份验证。
**运行**:
```sh
uv run pytest examples/29-testing-pytest/01-fixture-scopes -q
```
**预期输出**(3.12.9):
```text
.. [100%]
```
**依赖**:pytest(dev 组)。
**注意**:scope 越大越省初始化成本,但共享状态也越多;需要隔离的测试用 function,只读/昂贵资源用 module/session。