python
module_error
ai_generated
true
pytest.skip.Exception: 跳过:没有名为 'requests' 的模块
pytest.skip.Exception: Skipped: no module named 'requests'
ID: python/pytest-mark-skip-missing-import
80%修复率
92%置信度
0证据数
2025-01-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
根因分析
在测试中调用 pytest.skip() 但条件判断错误,或者 @pytest.mark.skipif 条件未正确评估。
English
在测试中调用 pytest.skip() 但条件判断错误,或者 @pytest.mark.skipif 条件未正确评估。
解决方案
-
98% 成功率 使用 importorskip
import pytest requests = pytest.importorskip('requests') -
90% 成功率 使用 skipif 装饰器
@pytest.mark.skipif(not ORG, reason='no requests') def test(): import requests
无效尝试
常见但无效的做法:
-
在模块顶层 try/except
50% 失败
尝试在导入时使用 try/except 并跳过,但 pytest 收集阶段可能报错
-
条件逻辑错误
40% 失败
尝试使用 sys.modules 检查但条件写反