Pytest Suite Generator
Generates a runnable pytest module for a target function or class — happy path, edge cases, and error cases with fixtures and parametrize.
What this skill does
Key features
- Covers happy path, boundary edge cases, and error paths in one module
- Uses fixtures and @pytest.mark.parametrize instead of copy-pasted test bodies
- Runs pytest to confirm the generated tests actually pass
- Asserts observable behavior and return values, not private implementation
Use cases
- Bootstrap a test module for an untested function before refactoring it
- Add regression coverage for a bug once its expected behavior is known
SKILL.md
The skill definition — its metadata and the exact instructions an agent follows. Copy it into a SKILL.md file in your agent's skills folder.
| name | pytest-suite |
|---|---|
| description | Generate a pytest module covering happy path, edge cases, and errors for a target function or class, then run it to confirm passing. |
| allowed-tools | Read, Grep, Write, Bash(pytest:*) |
| output | pytest test module |
| runner | pytest |
Musts
- Read the target function or class and understand its inputs, return values, and raised exceptions before writing any test.
- Cover the happy path, boundary and edge cases, and each documented error path with distinct assertions.
- Use
@pytest.mark.parametrizefor input variations and fixtures for shared setup instead of duplicating bodies. - Assert observable behavior — return values, side effects, raised exceptions — never private attributes or call internals.
- Run
pyteston the new module and confirm every test passes before reporting it done.
Guidelines
- Prefer
pytest.raises(ExceptionType)over broad try/except for error-path tests. - Avoid
time.sleep; if timing matters, use fakes, freezing, or dependency injection rather than real waits. - Give each test a name that states the scenario, e.g.
test_returns_zero_for_empty_input. - Keep one logical behavior per test so a failure names the exact broken case.
- Do not add trivial asserts like
assert result is not Noneas a test’s only check.
Output format
import pytest
from mymodule import parse_amount
@pytest.mark.parametrize("raw,expected", [
("10.50", 1050),
("0", 0),
("1000000.00", 100000000),
])
def test_parses_valid_amounts_to_cents(raw, expected):
assert parse_amount(raw) == expected
def test_rejects_negative_amount():
with pytest.raises(ValueError):
parse_amount("-5.00")
def test_rejects_non_numeric_input():
with pytest.raises(ValueError):
parse_amount("abc")
FAQ
Will it modify the code under test?
No. It reads the target to understand behavior and writes a separate test module. It does not change production code.
What if a generated test fails when run?
It investigates whether the test or the assumption is wrong, then fixes the test — it never weakens an assertion just to make it pass.
Before running any skill, read its instructions and the tools it's allowed to use, and test it on a safe target first. See LLM security best practices.