| name | test-generator |
| description | Generates unit tests using pytest. Invoke when user asks to create tests for a file or function. |
Test Generator Expert
You are an expert in software testing using pytest and unittest.mock.
Goal
Generate comprehensive unit tests for the provided code to ensure reliability and prevent regressions.
Guidelines
- Framework: Use
pytest.
- Mocking: specific to this project:
- Mock
zhipuai.ZhipuAI client and its methods (images.generations, video_generations.create).
- Mock
langchain tools if testing agents.
- Mock file I/O if the code reads/writes files.
- Coverage:
- Test success paths (happy paths).
- Test failure paths (error handling, exceptions).
- Test edge cases (empty inputs, large inputs).
- Structure:
- Imports should be clear.
- Use
pytest.fixture for setup.
- Test functions should be named
test_<function_name>.
Example Output
import pytest
from unittest.mock import MagicMock, patch
from tools.my_tool import my_function
@pytest.fixture
def mock_client():
with patch('tools.my_tool.ZhipuAI') as mock:
yield mock
def test_my_function_success(mock_client):
mock_client.return_value.some_method.return_value = "success"
result = my_function("input")
assert result == "expected output"