# 断言错误：断言nan等于1.0

- **ID:** `python/pytest-approx-nan`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest.approx比较时，实际值为NaN，导致失败。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   import math
if math.isnan(actual):
    pytest.fail('Actual value is NaN')
else:
    assert actual == pytest.approx(expected)
   ```
2. **** (90% 成功率)
   ```
   def assert_float_equal(actual, expected):
    if math.isnan(actual) or math.isnan(expected):
        assert math.isnan(actual) == math.isnan(expected)
    else:
        assert actual == pytest.approx(expected)
   ```

## 无效尝试

- **** — pytest.approx不支持NaN，需单独处理。 (60% 失败率)
- **** — 可能掩盖计算错误。 (90% 失败率)
