python
config_error
ai_generated
true
CollectionError: cannot collect 'test_foo' because it is not a function or class
ID: python/pytest-collection-error
80%Fix Rate
83%Confidence
0Evidence
2024-04-27First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
Root Cause
pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数
generic中文
pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数
Workarounds
-
95% success
my_foo = 123
-
80% success
collect_ignore = ['test_foo']
Dead Ends
Common approaches that don't work:
-
40% fail
如果变量在模块级别,pytest 可能仍会尝试收集
-
70% fail
只适用于类,不适用于变量