@@ -18,10 +18,15 @@ def test_main_with_agents_advanced(self):
18
18
result = praisonai .run ()
19
19
self .assertIn ('Task Output' , result )
20
20
except Exception as e :
21
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
22
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
23
- self .skipTest (f"Skipping due to API authentication: { e } " )
21
+ # Only skip if no API key provided or using test/fallback key
22
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
23
+ if (not api_key or
24
+ api_key .startswith ('sk-test-' ) or
25
+ api_key == 'nokey' or
26
+ 'fallback' in api_key ):
27
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
24
28
else :
29
+ # Real API key provided - test should fail, not skip
25
30
raise
26
31
27
32
def test_main_with_autogen_framework (self ):
@@ -30,10 +35,15 @@ def test_main_with_autogen_framework(self):
30
35
result = praisonai .run ()
31
36
self .assertTrue ('Task Output' in result or '### Output ###' in result )
32
37
except Exception as e :
33
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
34
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
35
- self .skipTest (f"Skipping due to API authentication: { e } " )
38
+ # Only skip if no API key provided or using test/fallback key
39
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
40
+ if (not api_key or
41
+ api_key .startswith ('sk-test-' ) or
42
+ api_key == 'nokey' or
43
+ 'fallback' in api_key ):
44
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
36
45
else :
46
+ # Real API key provided - test should fail, not skip
37
47
raise
38
48
39
49
def test_main_with_custom_framework (self ):
@@ -42,10 +52,15 @@ def test_main_with_custom_framework(self):
42
52
result = praisonai .run ()
43
53
self .assertIn ('Task Output' , result )
44
54
except Exception as e :
45
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
46
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
47
- self .skipTest (f"Skipping due to API authentication: { e } " )
55
+ # Only skip if no API key provided or using test/fallback key
56
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
57
+ if (not api_key or
58
+ api_key .startswith ('sk-test-' ) or
59
+ api_key == 'nokey' or
60
+ 'fallback' in api_key ):
61
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
48
62
else :
63
+ # Real API key provided - test should fail, not skip
49
64
raise
50
65
51
66
def test_main_with_internet_search_tool (self ):
@@ -54,10 +69,15 @@ def test_main_with_internet_search_tool(self):
54
69
result = praisonai .run ()
55
70
self .assertIn ('Task Output' , result )
56
71
except Exception as e :
57
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
58
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
59
- self .skipTest (f"Skipping due to API authentication: { e } " )
72
+ # Only skip if no API key provided or using test/fallback key
73
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
74
+ if (not api_key or
75
+ api_key .startswith ('sk-test-' ) or
76
+ api_key == 'nokey' or
77
+ 'fallback' in api_key ):
78
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
60
79
else :
80
+ # Real API key provided - test should fail, not skip
61
81
raise
62
82
63
83
def test_main_with_built_in_tool (self ):
@@ -66,10 +86,15 @@ def test_main_with_built_in_tool(self):
66
86
result = praisonai .run ()
67
87
self .assertIn ('Task Output' , result )
68
88
except Exception as e :
69
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
70
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
71
- self .skipTest (f"Skipping due to API authentication: { e } " )
89
+ # Only skip if no API key provided or using test/fallback key
90
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
91
+ if (not api_key or
92
+ api_key .startswith ('sk-test-' ) or
93
+ api_key == 'nokey' or
94
+ 'fallback' in api_key ):
95
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
72
96
else :
97
+ # Real API key provided - test should fail, not skip
73
98
raise
74
99
75
100
@@ -88,19 +113,29 @@ def run_command(self, command):
88
113
def test_praisonai_command (self ):
89
114
command = "praisonai --framework autogen --auto create movie script about cat in mars"
90
115
result = self .run_command (command )
91
- # Handle API authentication errors in command line output
92
- if ('Invalid API Key' in result or 'AuthenticationError' in result or
93
- 'InstructorRetryException' in result or '401' in result ):
94
- self .skipTest (f"Skipping due to API authentication in command output" )
116
+ # Only skip if no API key provided or using test/fallback key
117
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
118
+ if (not api_key or
119
+ api_key .startswith ('sk-test-' ) or
120
+ api_key == 'nokey' or
121
+ 'fallback' in api_key ):
122
+ if ('Invalid API Key' in result or 'AuthenticationError' in result or
123
+ 'InstructorRetryException' in result or '401' in result ):
124
+ self .skipTest (f"Skipping due to no valid API key provided" )
95
125
self .assertIn ('TERMINATE' , result )
96
126
97
127
def test_praisonai_init_command (self ):
98
128
command = "praisonai --framework autogen --init create movie script about cat in mars"
99
129
result = self .run_command (command )
100
- # Handle API authentication errors in command line output
101
- if ('Invalid API Key' in result or 'AuthenticationError' in result or
102
- 'InstructorRetryException' in result or '401' in result ):
103
- self .skipTest (f"Skipping due to API authentication in command output" )
130
+ # Only skip if no API key provided or using test/fallback key
131
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
132
+ if (not api_key or
133
+ api_key .startswith ('sk-test-' ) or
134
+ api_key == 'nokey' or
135
+ 'fallback' in api_key ):
136
+ if ('Invalid API Key' in result or 'AuthenticationError' in result or
137
+ 'InstructorRetryException' in result or '401' in result ):
138
+ self .skipTest (f"Skipping due to no valid API key provided" )
104
139
self .assertIn ('created successfully' , result )
105
140
106
141
class TestExamples (unittest .TestCase ):
@@ -119,10 +154,15 @@ def test_basic_example(self):
119
154
f"Expected meaningful result, got: { result } "
120
155
)
121
156
except Exception as e :
122
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
123
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
124
- self .skipTest (f"Skipping due to API authentication: { e } " )
157
+ # Only skip if no API key provided or using test/fallback key
158
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
159
+ if (not api_key or
160
+ api_key .startswith ('sk-test-' ) or
161
+ api_key == 'nokey' or
162
+ 'fallback' in api_key ):
163
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
125
164
else :
165
+ # Real API key provided - test should fail, not skip
126
166
raise
127
167
128
168
def test_advanced_example (self ):
@@ -140,10 +180,15 @@ def test_advanced_example(self):
140
180
f"Expected meaningful result, got: { result } "
141
181
)
142
182
except Exception as e :
143
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
144
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
145
- self .skipTest (f"Skipping due to API authentication: { e } " )
183
+ # Only skip if no API key provided or using test/fallback key
184
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
185
+ if (not api_key or
186
+ api_key .startswith ('sk-test-' ) or
187
+ api_key == 'nokey' or
188
+ 'fallback' in api_key ):
189
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
146
190
else :
191
+ # Real API key provided - test should fail, not skip
147
192
raise
148
193
149
194
def test_auto_example (self ):
@@ -161,10 +206,15 @@ def test_auto_example(self):
161
206
f"Expected meaningful result, got: { result } "
162
207
)
163
208
except Exception as e :
164
- if ('Invalid API Key' in str (e ) or 'AuthenticationError' in str (e ) or
165
- 'InstructorRetryException' in str (e ) or '401' in str (e )):
166
- self .skipTest (f"Skipping due to API authentication: { e } " )
209
+ # Only skip if no API key provided or using test/fallback key
210
+ api_key = os .environ .get ('OPENAI_API_KEY' , '' )
211
+ if (not api_key or
212
+ api_key .startswith ('sk-test-' ) or
213
+ api_key == 'nokey' or
214
+ 'fallback' in api_key ):
215
+ self .skipTest (f"Skipping due to no valid API key provided: { e } " )
167
216
else :
217
+ # Real API key provided - test should fail, not skip
168
218
raise
169
219
170
220
if __name__ == '__main__' :
0 commit comments