# unittest.SkipTest: Skipped: 'numpy' is not installed

- **ID:** `python/unittest-skip-unless-import-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

使用 @unittest.skipUnless 但条件判断错误，导致测试被意外跳过。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |

## Workarounds

1. **使用 find_spec 检查** (95% success)
   ```
   @unittest.skipUnless(importlib.util.find_spec('numpy'), 'numpy not installed')
def test_numpy(self): pass
   ```
2. **模块级导入检查** (90% success)
   ```
   try:
    import numpy
except ImportError:
    numpy = None
@unittest.skipIf(numpy is None, 'numpy missing')
def test(...):
   ```

## Dead Ends

- **在测试内部 try/except** — 尝试使用 try/except ImportError 包裹整个测试，但跳过逻辑不灵活 (40% fail)
- **手动设置标志** — 尝试手动设置 skip 标志但忘记恢复 (30% fail)
