# 属性错误：'LogCaptureFixture' 对象没有属性 'records'

- **ID:** `python/pytest-capture-caplog-attribute-error`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用了过时或不正确的 caplog API；'records' 在 pytest 6.x 中引入，但在旧版本或 caplog 未正确初始化时可能不可用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## 解决方案

1. **Upgrade pytest to version 6.0 or later to support caplog.records.** (95% 成功率)
   ```
   pip install pytest>=6.0
   ```
2. **Use caplog.record_tuples instead of caplog.records for backward compatibility.** (85% 成功率)
   ```
   assert ('module', logging.INFO, 'message') in caplog.record_tuples
   ```

## 无效尝试

- **Trying to access caplog.records without checking pytest version** — If pytest version is below 6.0, 'records' attribute doesn't exist. (70% 失败率)
- **Using caplog.text instead of caplog.records for log level checks** — caplog.text returns a string, not log records, so level filtering fails. (65% 失败率)
