# 类型错误：skipIf() 参数 1 必须是布尔值，而不是字符串

- **ID:** `python/unittest-skipif-condition-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

@unittest.skipIf 装饰器接收了字符串条件而非布尔表达式，通常是由于缺少调用或语法错误。

## 版本兼容性

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

## 解决方案

1. **Ensure the condition is a boolean expression, not a string.** (90% 成功率)
   ```
   @unittest.skipIf(sys.version_info < (3, 9), 'Requires Python 3.9+')
   ```
2. **Use skipUnless for inverse logic if condition is complex.** (85% 成功率)
   ```
   @unittest.skipUnless(hasattr(module, 'function'), 'Module missing function')
   ```

## 无效尝试

- **Using skipIf with a string literal like 'True'** — String 'True' is not a boolean; it will always evaluate to True (truthy) but cause TypeError. (80% 失败率)
- **Wrapping the condition in quotes to avoid syntax errors** — Quotes make it a string, which is not accepted by skipIf. (75% 失败率)
