|
4 | 4 |
|
5 | 5 | import pydantic_core
|
6 | 6 | import pytest
|
| 7 | +from _pytest.logging import LogCaptureFixture |
7 | 8 | from inline_snapshot import snapshot
|
8 | 9 | from pydantic import BaseModel, Field
|
9 | 10 | from pydantic_core import PydanticSerializationError
|
@@ -532,3 +533,36 @@ def ctx_tool(ctx: RunContext[int], x: int) -> int:
|
532 | 533 | """)
|
533 | 534 | result = mod.agent.run_sync('foobar', deps=5)
|
534 | 535 | assert result.data == snapshot('{"ctx_tool":5}')
|
| 536 | + |
| 537 | + |
| 538 | +async def tool_without_return_annotation_in_docstring() -> str: # pragma: no cover |
| 539 | + """A tool that documents what it returns but doesn't have a return annotation in the docstring. |
| 540 | +
|
| 541 | + Returns: |
| 542 | + A value. |
| 543 | + """ |
| 544 | + |
| 545 | + return '' |
| 546 | + |
| 547 | + |
| 548 | +def test_suppress_griffe_logging(set_event_loop: None, caplog: LogCaptureFixture): |
| 549 | + # This would cause griffe to emit a warning log if we didn't suppress the griffe logging. |
| 550 | + |
| 551 | + agent = Agent(FunctionModel(get_json_schema)) |
| 552 | + agent.tool_plain(tool_without_return_annotation_in_docstring) |
| 553 | + |
| 554 | + result = agent.run_sync('') |
| 555 | + json_schema = json.loads(result.data) |
| 556 | + assert json_schema == snapshot( |
| 557 | + { |
| 558 | + 'description': "A tool that documents what it returns but doesn't have a " |
| 559 | + 'return annotation in the docstring.', |
| 560 | + 'name': 'tool_without_return_annotation_in_docstring', |
| 561 | + 'outer_typed_dict_key': None, |
| 562 | + 'parameters_json_schema': {'additionalProperties': False, 'properties': {}, 'type': 'object'}, |
| 563 | + } |
| 564 | + ) |
| 565 | + |
| 566 | + # Without suppressing griffe logging, we get: |
| 567 | + # assert caplog.messages == snapshot(['<module>:4: No type or annotation for returned value 1']) |
| 568 | + assert caplog.messages == snapshot([]) |
0 commit comments