# Test Generator

> Generates unit tests using pytest. Invoke when user asks to create tests for a file or function.

- Skill: `phuhao00/test-generator` (Agent Skill)
- Install (CLI): `npx skillmds@latest add phuhao00/test-generator`
- Raw SKILL.md: https://api.skillmd.com/api/skills/phuhao00/test-generator/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: phuhao00 (https://skillmd.com/u/phuhao00)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/phuhao00/test-generator

---


# 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
1.  **Framework**: Use `pytest`.
2.  **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.
3.  **Coverage**:
    -   Test success paths (happy paths).
    -   Test failure paths (error handling, exceptions).
    -   Test edge cases (empty inputs, large inputs).
4.  **Structure**:
    -   Imports should be clear.
    -   Use `pytest.fixture` for setup.
    -   Test functions should be named `test_<function_name>`.

## Example Output
```python
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):
    # Setup
    mock_client.return_value.some_method.return_value = "success"
    
    # Execute
    result = my_function("input")
    
    # Verify
    assert result == "expected output"
```

