Skip to content

[BUG] PytestCollectionWarning from 4 helper classes named Test* in lib/crewai/tests #9685

Done

Description

@paulinawn

Description

Four module-level helper classes in lib/crewai/tests are named Test* and inherit an __init__ from Pydantic-based parents (Flow, FlowState, BaseEvent, BaseModel). pytest treats Test* classes as test containers, can't instantiate them, and emits a PytestCollectionWarning on every run. No tests fail; it's test-output noise that can hide real warnings and would break the suite if warnings were ever turned into errors.

File:line Class Parent
lib/crewai/tests/agents/test_lite_agent.py:272 TestFlow Flow
lib/crewai/tests/test_flow_persistence.py:15 TestState FlowState
lib/crewai/tests/utilities/events/test_crewai_event_bus.py:8 TestEvent BaseEvent
lib/crewai/tests/utilities/test_training_converter.py:9 TestModel BaseModel

Steps to Reproduce

  1. uv sync on current main
  2. uv run pytest lib/crewai/tests --collect-only -q -n 0
  3. See the warnings summary: cannot collect test class '...' because it has a __init__ constructor

Expected behavior

No PytestCollectionWarning: helper classes are not treated as test classes by pytest.

Screenshots/Code snippets

Example (lib/crewai/tests/utilities/events/test_crewai_event_bus.py:8):

class TestEvent(BaseEvent):

Operating System

Other (specify in additional context)

Python Version

3.12

crewAI Version

1.15.44 (main @ 3c53d50)

crewAI Tools Version

1.15.44 (workspace, same commit)

Virtual Environment

Venv

Evidence

From uv run pytest lib/crewai/tests --collect-only -q -n 0:

lib/crewai/tests/agents/test_lite_agent.py:272: PytestCollectionWarning: cannot collect test class 'TestFlow' because it has a __init__ constructor (from: lib/crewai/tests/agents/test_lite_agent.py)
lib/crewai/tests/test_flow_persistence.py:15: PytestCollectionWarning: cannot collect test class 'TestState' because it has a __init__ constructor (from: lib/crewai/tests/test_flow_persistence.py)
lib/crewai/tests/utilities/events/test_crewai_event_bus.py:8: PytestCollectionWarning: cannot collect test class 'TestEvent' because it has a __init__ constructor (from: lib/crewai/tests/utilities/events/test_crewai_event_bus.py)
lib/crewai/tests/utilities/test_training_converter.py:9: PytestCollectionWarning: cannot collect test class 'TestModel' because it has a __init__ constructor (from: lib/crewai/tests/utilities/test_training_converter.py)

Cross-checked with git grep -n -E "^\s*class Test\w*\(\w+" -- lib/crewai/tests: these are the only module-level helper classes affected. Nested Test* classes defined inside test functions are not collected by pytest.

The warning has been around for a while (visible in #2610 from April 2025, and noted in #9165).

Possible Solution

Test-only change, no runtime impact. Either:

  • rename the helpers (e.g. TestFlow → SampleFlow), or
  • add __test__ = False to each class, pytest's documented opt-out.

Happy to open a PR. Do you have a preference between the two?

Additional context

Environment: Ubuntu 26.04.1 LTS on WSL2 (Windows 11), Python 3.13.18, uv 0.13.9. The form's dropdowns only offer up to Python 3.12 and Ubuntu 24.04; the warning is independent of OS and Python version.
Issue prepared with AI assistance.

Activity

  1. added
    bug
    on Nov 23, 2026
  2. SIDDARTHAREDDY8 commented on Nov 23, 2026

    @SIDDARTHAREDDY8
    Contributor

    Verified all four on current main (read-only, no test run). The mechanism differs per class: TestFlow (test_lite_agent.py:272) defines its own __init__(self, llm, tools), while the other three inherit one from Pydantic parents (TestState from FlowState, TestEvent from BaseEvent, TestModel from BaseModel). The other TestFlow definitions in test_lite_agent.py (lines 761, 789) are nested inside test functions, so only the module-level one at 272 is collected — same for the nested TestFlow in test_flow_persistence.py.

    On rename vs __test__ = False: I would go with rename. A code search shows __test__ = False has no precedent anywhere in the repo, so it would introduce a new idiom, while renaming is contained — each helper is only used inside its own file, and the name TestFlow is already independently redefined per test file (e.g. test_flow.py, test_streaming.py). One thing to watch when renaming: test_training_converter.py has a real test class TestTrainingConverter right below the TestModel helper, so only the helper should be renamed.

  3. aditiraj0129-netizen commented on Nov 23, 2026

    @aditiraj0129-netizen

    Hi, I'd like to take this. Plan: add __test__ = False to the 4 module-level helper classes (TestFlow, TestState, TestEvent, TestModel) so pytest stops trying to collect them. No renames, minimal diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions