python
config_error
ai_generated
true
收集错误:无法收集 'test_foo',因为它不是函数或类
CollectionError: cannot collect 'test_foo' because it is not a function or class
ID: python/pytest-collection-error
80%修复率
83%置信度
0证据数
2024-04-27首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
根因分析
pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数
English
pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数
解决方案
-
95% 成功率
my_foo = 123
-
80% 成功率
collect_ignore = ['test_foo']
无效尝试
常见但无效的做法:
-
40% 失败
如果变量在模块级别,pytest 可能仍会尝试收集
-
70% 失败
只适用于类,不适用于变量