python
runtime_error
ai_generated
true
Skipped: 评估条件 'sys.platform == "win32"' 引发 AttributeError: 模块 'sys' 没有属性 'platform'
Skipped: evaluating condition 'sys.platform == "win32"' raised AttributeError: module 'sys' has no attribute 'platform'
ID: python/pytest-skipif-condition-evaluation-error
80%修复率
85%置信度
0证据数
2025-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
@pytest.mark.skipif 中的条件引用了一个不存在的属性,通常是由于拼写错误(例如 'platfom' 而不是 'platform')。
English
The condition in @pytest.mark.skipif references a non-existent attribute, often due to a typo (e.g., 'platfom' instead of 'platform').
解决方案
-
95% 成功率
Correct the attribute name: `@pytest.mark.skipif(sys.platform == 'win32', reason='not on Windows')`
-
90% 成功率
Use a function for complex conditions: `def is_win(): return sys.platform == 'win32'; @pytest.mark.skipif(is_win())`
无效尝试
常见但无效的做法:
-
80% 失败
This may cause the test to run on unsupported platforms and fail.
-
90% 失败
The condition string is evaluated at module level; try-except is not supported in that context.