示例工程 29-testing-pytest
29-testing-pytest/05-monkeypatch-env/README.md
# 05 · monkeypatch-env
**演示**:用 `monkeypatch.setenv`/`delenv` 临时改环境变量,测试结束后自动恢复;配置读取用 `os.environ.get`。
**运行**:
```sh
uv run pytest examples/29-testing-pytest/05-monkeypatch-env -q
```
**预期输出**(3.12.9):
```text
... [100%]
```
**依赖**:pytest(dev 组)。
**注意**:环境变量永远是字符串;`monkeypatch` 也能替换属性/方法,但跨模块导入的引用仍要打到使用处(见 04)。