mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Fix CrewBase decorator linting errors when accessing self.agents or self.tasks
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
53
tests/test_crewbase_linting.py
Normal file
53
tests/test_crewbase_linting.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
from crewai import Agent, Crew, Task, Process
|
||||
from crewai.project import CrewBase, agent, task, crew
|
||||
|
||||
|
||||
@CrewBase
|
||||
class TestCrewBaseLinting:
|
||||
"""Test class for verifying that CrewBase doesn't cause linting errors."""
|
||||
|
||||
# Override config paths to avoid loading non-existent files
|
||||
agents_config = {}
|
||||
tasks_config = {}
|
||||
|
||||
@agent
|
||||
def agent_one(self) -> Agent:
|
||||
return Agent(
|
||||
role="Test Agent",
|
||||
goal="Test Goal",
|
||||
backstory="Test Backstory"
|
||||
)
|
||||
|
||||
@task
|
||||
def task_one(self) -> Task:
|
||||
# Create a task with an agent assigned to it
|
||||
return Task(
|
||||
description="Test Description",
|
||||
expected_output="Test Output",
|
||||
agent=self.agent_one() # Assign the agent to the task
|
||||
)
|
||||
|
||||
@crew
|
||||
def crew(self) -> Crew:
|
||||
# Access self.agents and self.tasks to verify no linting errors
|
||||
return Crew(
|
||||
agents=self.agents, # Should not cause linting errors
|
||||
tasks=self.tasks, # Should not cause linting errors
|
||||
process=Process.sequential,
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
|
||||
def test_crewbase_linting():
|
||||
"""Test that CrewBase doesn't cause linting errors."""
|
||||
crew_instance = TestCrewBaseLinting()
|
||||
crew_obj = crew_instance.crew()
|
||||
|
||||
# Verify that agents and tasks are accessible
|
||||
assert len(crew_instance.agents) > 0
|
||||
assert len(crew_instance.tasks) > 0
|
||||
|
||||
# Verify that the crew object was created correctly
|
||||
assert crew_obj is not None
|
||||
assert isinstance(crew_obj, Crew)
|
||||
Reference in New Issue
Block a user