@@ -39,7 +39,7 @@ async def test_one_parameter_raises_error(self, mock_run_context):
39
39
def invalid_instructions (context ):
40
40
return "Should fail"
41
41
42
- agent = Agent (name = "test_agent" , instructions = invalid_instructions )
42
+ agent = Agent (name = "test_agent" , instructions = invalid_instructions ) # type: ignore[arg-type]
43
43
44
44
with pytest .raises (TypeError ) as exc_info :
45
45
await agent .get_system_prompt (mock_run_context )
@@ -53,7 +53,7 @@ async def test_three_parameters_raises_error(self, mock_run_context):
53
53
def invalid_instructions (context , agent , extra ):
54
54
return "Should fail"
55
55
56
- agent = Agent (name = "test_agent" , instructions = invalid_instructions )
56
+ agent = Agent (name = "test_agent" , instructions = invalid_instructions ) # type: ignore[arg-type]
57
57
58
58
with pytest .raises (TypeError ) as exc_info :
59
59
await agent .get_system_prompt (mock_run_context )
@@ -67,7 +67,7 @@ async def test_zero_parameters_raises_error(self, mock_run_context):
67
67
def invalid_instructions ():
68
68
return "Should fail"
69
69
70
- agent = Agent (name = "test_agent" , instructions = invalid_instructions )
70
+ agent = Agent (name = "test_agent" , instructions = invalid_instructions ) # type: ignore[arg-type]
71
71
72
72
with pytest .raises (TypeError ) as exc_info :
73
73
await agent .get_system_prompt (mock_run_context )
@@ -76,16 +76,18 @@ def invalid_instructions():
76
76
assert "but got 0" in str (exc_info .value )
77
77
78
78
@pytest .mark .asyncio
79
- async def test_function_with_args_kwargs_passes (self , mock_run_context ):
80
- """Test that function with *args/**kwargs still works (edge case) """
79
+ async def test_function_with_args_kwargs_fails (self , mock_run_context ):
80
+ """Test that function with *args/**kwargs fails validation """
81
81
def flexible_instructions (context , agent , * args , ** kwargs ):
82
82
return "Flexible instructions"
83
83
84
84
agent = Agent (name = "test_agent" , instructions = flexible_instructions )
85
- # This should potentially pass as it can accept the 2 required args
86
- # Adjust this test based on your desired behavior
87
- result = await agent .get_system_prompt (mock_run_context )
88
- assert result == "Flexible instructions"
85
+
86
+ with pytest .raises (TypeError ) as exc_info :
87
+ await agent .get_system_prompt (mock_run_context )
88
+
89
+ assert "must accept exactly 2 arguments" in str (exc_info .value )
90
+ assert "but got" in str (exc_info .value )
89
91
90
92
@pytest .mark .asyncio
91
93
async def test_string_instructions_still_work (self , mock_run_context ):
@@ -102,10 +104,10 @@ async def test_none_instructions_return_none(self, mock_run_context):
102
104
assert result is None
103
105
104
106
@pytest .mark .asyncio
105
- async def test_non_callable_instructions_log_error (self , mock_run_context , caplog ):
106
- """Test that non-callable instructions log an error """
107
- agent = Agent ( name = "test_agent" , instructions = 123 ) # Invalid type
108
- result = await agent . get_system_prompt ( mock_run_context )
109
- assert result is None
110
- # Check that error was logged (adjust based on actual logging setup )
111
- # assert "Instructions must be a string or a function " in caplog.text
107
+ async def test_non_callable_instructions_raises_error (self , mock_run_context ):
108
+ """Test that non-callable instructions raise a TypeError during initialization """
109
+ with pytest . raises ( TypeError ) as exc_info :
110
+ Agent ( name = "test_agent" , instructions = 123 ) # type: ignore[arg-type]
111
+
112
+ assert "Agent instructions must be a string, callable, or None" in str ( exc_info . value )
113
+ assert "got int " in str ( exc_info . value )
0 commit comments