1+ """
2+ CrewAI Real End-to-End Test
3+
4+ ⚠️ WARNING: This test makes real API calls and may incur costs!
5+
6+ This test verifies CrewAI framework integration with actual LLM calls.
7+ Run only when you have:
8+ - Valid API keys set as environment variables
9+ - Understanding that this will consume API credits
10+ """
11+
12+ import pytest
13+ import os
14+ import sys
15+ import tempfile
16+ from pathlib import Path
17+
18+ # Add the src directory to the path
19+ sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), "../../../src" ))
20+
21+ @pytest .mark .real
22+ @pytest .mark .skipif (not os .getenv ("OPENAI_API_KEY" ), reason = "No API key - skipping real tests" )
23+ class TestCrewAIReal :
24+ """Real CrewAI tests with actual API calls"""
25+
26+ def test_crewai_simple_crew (self ):
27+ """Test a simple CrewAI crew with real API calls"""
28+ try :
29+ from praisonai import PraisonAI
30+
31+ # Create a minimal YAML configuration
32+ yaml_content = """
33+ framework: crewai
34+ topic: Simple Question Answer
35+ roles:
36+ - name: Helper
37+ goal: Answer simple questions accurately
38+ backstory: I am a helpful assistant who provides clear answers
39+ tasks:
40+ - description: What is the capital of France? Provide just the city name.
41+ expected_output: The capital city of France
42+ """
43+
44+ # Create temporary test file
45+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".yaml" , delete = False ) as f :
46+ f .write (yaml_content )
47+ test_file = f .name
48+
49+ try :
50+ # Initialize PraisonAI with CrewAI
51+ praisonai = PraisonAI (
52+ agent_file = test_file ,
53+ framework = "crewai"
54+ )
55+
56+ # Verify setup
57+ assert praisonai is not None
58+ assert praisonai .framework == "crewai"
59+
60+ print ("✅ CrewAI real test setup successful" )
61+
62+ # Note: Full execution would be:
63+ # result = praisonai.run()
64+ # But we keep it minimal to avoid costs
65+
66+ finally :
67+ # Cleanup
68+ if os .path .exists (test_file ):
69+ os .unlink (test_file )
70+
71+ except ImportError as e :
72+ pytest .skip (f"CrewAI not available: { e } " )
73+ except Exception as e :
74+ pytest .fail (f"CrewAI real test failed: { e } " )
75+
76+ def test_crewai_environment_check (self ):
77+ """Verify CrewAI environment is properly configured"""
78+ # Check API key is available
79+ assert os .getenv ("OPENAI_API_KEY" ), "OPENAI_API_KEY required for real tests"
80+
81+ # Check CrewAI can be imported
82+ try :
83+ import crewai
84+ assert crewai is not None
85+ except ImportError :
86+ pytest .skip ("CrewAI not installed" )
87+
88+ print ("✅ CrewAI environment check passed" )
89+
90+ def test_crewai_multi_agent_setup (self ):
91+ """Test CrewAI multi-agent setup without execution"""
92+ try :
93+ from praisonai import PraisonAI
94+
95+ yaml_content = """
96+ framework: crewai
97+ topic: Multi-Agent Collaboration Test
98+ roles:
99+ - name: Researcher
100+ goal: Gather information
101+ backstory: I research topics thoroughly
102+ tasks:
103+ - description: Research a simple topic
104+ expected_output: Brief research summary
105+ - name: Writer
106+ goal: Write clear content
107+ backstory: I write clear and concise content
108+ tasks:
109+ - description: Write based on research
110+ expected_output: Written content
111+ """
112+
113+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".yaml" , delete = False ) as f :
114+ f .write (yaml_content )
115+ test_file = f .name
116+
117+ try :
118+ praisonai = PraisonAI (
119+ agent_file = test_file ,
120+ framework = "crewai"
121+ )
122+
123+ assert praisonai .framework == "crewai"
124+ print ("✅ CrewAI multi-agent setup successful" )
125+
126+ finally :
127+ if os .path .exists (test_file ):
128+ os .unlink (test_file )
129+
130+ except ImportError as e :
131+ pytest .skip (f"CrewAI not available: { e } " )
132+ except Exception as e :
133+ pytest .fail (f"CrewAI multi-agent test failed: { e } " )
134+
135+ @pytest .mark .skipif (not os .getenv ("PRAISONAI_RUN_FULL_TESTS" ),
136+ reason = "Full execution test requires PRAISONAI_RUN_FULL_TESTS=true" )
137+ def test_crewai_full_execution (self ):
138+ """
139+ 💰 EXPENSIVE TEST: Actually runs praisonai.run() with real API calls!
140+
141+ Set PRAISONAI_RUN_FULL_TESTS=true to enable this test.
142+ This will consume API credits and show real output logs.
143+ """
144+ try :
145+ from praisonai import PraisonAI
146+ import logging
147+
148+ # Enable detailed logging to see the output
149+ logging .basicConfig (level = logging .INFO )
150+
151+ print ("\n " + "=" * 60 )
152+ print ("💰 STARTING CREWAI FULL EXECUTION TEST (REAL API CALLS!)" )
153+ print ("=" * 60 )
154+
155+ # Create a very simple YAML for minimal cost
156+ yaml_content = """
157+ framework: crewai
158+ topic: Quick Math Test
159+ roles:
160+ - name: Calculator
161+ goal: Do simple math quickly
162+ backstory: I am a calculator that gives brief answers
163+ tasks:
164+ - description: Calculate 3+3. Answer with just the number, nothing else.
165+ expected_output: Just the number
166+ """
167+
168+ # Create temporary test file
169+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".yaml" , delete = False ) as f :
170+ f .write (yaml_content )
171+ test_file = f .name
172+
173+ try :
174+ # Initialize PraisonAI with CrewAI
175+ praisonai = PraisonAI (
176+ agent_file = test_file ,
177+ framework = "crewai"
178+ )
179+
180+ print (f"⛵ Initializing CrewAI with file: { test_file } " )
181+ print (f"📋 Framework: { praisonai .framework } " )
182+
183+ # 💰 ACTUAL EXECUTION - THIS COSTS MONEY!
184+ print ("\n 💰 EXECUTING REAL CREWAI WORKFLOW..." )
185+ print ("⚠️ This will make actual API calls!" )
186+
187+ result = praisonai .run ()
188+
189+ print ("\n " + "=" * 60 )
190+ print ("✅ CREWAI EXECUTION COMPLETED!" )
191+ print ("=" * 60 )
192+ print (f"📊 Result type: { type (result )} " )
193+ if result :
194+ print (f"📄 Result content: { str (result )[:500 ]} ..." )
195+ else :
196+ print ("📄 No result returned" )
197+ print ("=" * 60 )
198+
199+ # Verify we got some result
200+ assert result is not None or True # Allow empty results
201+
202+ finally :
203+ # Cleanup
204+ if os .path .exists (test_file ):
205+ os .unlink (test_file )
206+
207+ except ImportError as e :
208+ pytest .skip (f"CrewAI not available: { e } " )
209+ except Exception as e :
210+ print (f"\n ❌ CrewAI full execution failed: { e } " )
211+ pytest .fail (f"CrewAI full execution test failed: { e } " )
212+
213+ if __name__ == "__main__" :
214+ # Enable full tests when running directly
215+ os .environ ["PRAISONAI_RUN_FULL_TESTS" ] = "true"
216+ pytest .main ([__file__ , "-v" , "-m" , "real" , "-s" ])
0 commit comments