# 03 · capsys-and-tmp-path **演示**:`capsys` 捕获 `print` 的 stdout/stderr;`tmp_path` 给每个测试独立临时目录,读写文件不污染仓库。 **运行**: ```sh uv run pytest examples/29-testing-pytest/03-capsys-and-tmp-path -q ``` **预期输出**(3.12.9): ```text ... [100%] ``` **依赖**:pytest(dev 组)。 **注意**:`capsys` 抓 Python 层输出;`capfd` 抓文件描述符(C 扩展/子进程)。`tmp_path` 不需要手动清理。