python-test-generator
Write a runnable pytest test file for a Python module or function, covering happy paths, edge cases and error cases. Use when the user asks to write, add or generate tests / unit tests / pytest for Python code. Not for other languages or for fixing failing tests.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Badge for your README
Markdown
[](/listings/daillyteen3056-rgb--python-test-generator-skill)HTML
<a href="/listings/daillyteen3056-rgb--python-test-generator-skill"><img src="/api/listings/daillyteen3056-rgb--python-test-generator-skill/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
**macOS / Linux**
git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git ~/.claude/skills/python-test-generator
**Windows (PowerShell)**
git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git "$env:USERPROFILE\.claude\skills\python-test-generator"
Claude Code picks it up automatically, so no restart is needed. If your `skills` folder did not exist when the session started, run `/reload-skills`.
To use it in a single project instead, clone into `.claude/skills/python-test-generator` inside that project.
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
SKILL.md · Manifest · 60 lines
- ---
- name: python-test-generator
- description: Write a runnable pytest test file for a Python module or function, covering happy paths, edge cases and error cases. Use when the user asks to write, add or generate tests / unit tests / pytest for Python code. Not for other languages or for fixing failing tests.
- ---
- # Python test generator
- Produce a single pytest file that runs green against the current code without edits.
- ## When to use
- - "write tests for utils.py", "add unit tests for `parse_date`", "generate pytest for this module"
- - The target is Python source in the repo.
- ## When NOT to use
- - Non-Python code → say so and stop.
- - The user wants an existing failing test debugged → debug instead.
- - The user wants integration/e2e tests against live services → ask which services to mock first.
- ## Steps
- 1. Read the target file completely. List every public function/class/method (names not starting with `_`).
- 2. Check how the project already tests: look for `tests/`, `conftest.py`, `pytest.ini`/`pyproject.toml` `[tool.pytest]`, existing fixtures and naming. Follow those conventions.
- 3. For each public unit, plan cases:
- - **Happy path** – typical input → expected output.
- - **Edge cases** – empty, zero, None, boundaries, unicode, very large inputs, as relevant to the signature.
- - **Error cases** – inputs that should raise; assert the exact exception type with `pytest.raises`.
- 4. Isolate side effects: use `tmp_path` for files, `monkeypatch` for env vars/time, `unittest.mock` for network/DB/subprocess. Never hit the network.
- 5. Use `@pytest.mark.parametrize` when 3+ cases share a shape.
- 6. Write the file to `tests/test_<module>.py` (or the project's existing location/pattern).
- 7. Run `pytest <file> -q`. If a test fails, decide: test bug → fix the test; real code bug → keep the test, mark it `@pytest.mark.xfail(reason="...")` and tell the user.
- ## Output constraints
- - One file, imports at top, no placeholder `pass` tests, no `assert True`.
- - Test names describe behaviour: `test_parse_date_rejects_empty_string`.
- - Expected values must be derived from the code's actual logic, never guessed.
- - End with a 2–4 line summary: file path, number of tests, anything marked xfail.
- ## Example
- Input: `def slugify(s: str) -> str` that lowercases, strips and replaces spaces with `-`.
- ```python
- import pytest
- from app.text import slugify
- @pytest.mark.parametrize("raw,expected", [
- ("Hello World", "hello-world"),
- (" padded ", "padded"),
- ("", ""),
- ])
- def test_slugify_basic(raw, expected):
- assert slugify(raw) == expected
- def test_slugify_rejects_none():
- with pytest.raises(AttributeError):
- slugify(None)
- ```
- ## Anti-patterns
- - Testing private helpers instead of public behaviour.
- - Copying the implementation into the test to compute expected values.
- - Snapshotting huge outputs instead of asserting the meaningful parts.
- - Leaving tests that only pass because of mocked-away logic.
README.md · README · 51 lines
- # python-test-generator — a free Claude Code skill
- A [Claude Code](https://code.claude.com/docs/en/skills) skill that writes a **runnable pytest file** for any Python module, covering happy paths, edge cases and error cases. It then runs the file and fixes its own mistakes.
- ## Install
- **macOS / Linux**
- ```bash
- git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git ~/.claude/skills/python-test-generator
- ```
- **Windows (PowerShell)**
- ```powershell
- git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git "$env:USERPROFILE\.claude\skills\python-test-generator"
- ```
- Claude Code picks it up automatically, so no restart is needed. If your `skills` folder did not exist when the session started, run `/reload-skills`.
- To use it in a single project instead, clone into `.claude/skills/python-test-generator` inside that project.
- ## Use
- Just ask:
- - "write tests for utils.py"
- - "add unit tests for `parse_date`"
- - "generate pytest for this module"
- Or call it directly with `/python-test-generator`.
- ## What it does
- 1. Reads the target file and lists every public function, class and method.
- 2. Follows your project's existing test layout, `conftest.py` and fixtures.
- 3. Plans happy-path, edge and error cases for each unit and uses `pytest.raises` for exact exception types.
- 4. Isolates side effects with `tmp_path`, `monkeypatch` and `unittest.mock`, so it never touches the network.
- 5. Uses `@pytest.mark.parametrize` when 3 or more cases share a shape.
- 6. Writes `tests/test_<module>.py` and runs it. A wrong test gets fixed. A real bug in your code gets an `xfail` marker, and the skill tells you about it.
- It will not write placeholder tests, `assert True`, or expected values copied from the implementation.
- ## More skills
- - **[Claude Code Skills Pack](https://daillyteen.gumroad.com/l/wapct)**: this skill plus 5 more dev skills (commit messages, PR descriptions, docstrings, `.env.example` generation, Dockerfile optimizer).
- - **[SkillNest](https://skillnest.dev)**: a searchable directory of 560+ free Claude Code skills.
- ## License
- [MIT](LICENSE). Independent project, not affiliated with or endorsed by Anthropic.
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.