python config_error ai_generated true

CollectionError: cannot collect 'test_foo' because it is not a function or class

ID: python/pytest-collection-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-04-27First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.4.0 active

Root Cause

pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数

generic

中文

pytest 试图收集一个名为 test_foo 的变量或对象,而不是测试函数

Workarounds

  1. 95% success
    my_foo = 123
  2. 80% success
    collect_ignore = ['test_foo']

Dead Ends

Common approaches that don't work:

  1. 40% fail

    如果变量在模块级别,pytest 可能仍会尝试收集

  2. 70% fail

    只适用于类,不适用于变量