Repository navigation
Description
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
uv syncon currentmainuv run pytest lib/crewai/tests --collect-only -q -n 0- 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__ = Falseto 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
SIDDARTHAREDDY8 commentedon Nov 23, 2026
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 (TestStatefromFlowState,TestEventfromBaseEvent,TestModelfromBaseModel). The otherTestFlowdefinitions 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 nestedTestFlowin test_flow_persistence.py.On rename vs
__test__ = False: I would go with rename. A code search shows__test__ = Falsehas 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 nameTestFlowis 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 classTestTrainingConverterright below theTestModelhelper, so only the helper should be renamed.aditiraj0129-netizen commentedon Nov 23, 2026
Hi, I'd like to take this. Plan: add
__test__ = Falseto the 4 module-level helper classes (TestFlow, TestState, TestEvent, TestModel) so pytest stops trying to collect them. No renames, minimal diff.test: stop pytest collecting Test* helper classes (crewAIInc#9685)