Skip to content
Back to search

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
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/daillyteen3056-rgb--python-test-generator-skill/badge.svg)](/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

i

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
  1. ---
  2. name: python-test-generator
  3. 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.
  4. ---
  5. # Python test generator
  6. Produce a single pytest file that runs green against the current code without edits.
  7. ## When to use
  8. - "write tests for utils.py", "add unit tests for `parse_date`", "generate pytest for this module"
  9. - The target is Python source in the repo.
  10. ## When NOT to use
  11. - Non-Python code → say so and stop.
  12. - The user wants an existing failing test debugged → debug instead.
  13. - The user wants integration/e2e tests against live services → ask which services to mock first.
  14. ## Steps
  15. 1. Read the target file completely. List every public function/class/method (names not starting with `_`).
  16. 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.
  17. 3. For each public unit, plan cases:
  18. - **Happy path** – typical input → expected output.
  19. - **Edge cases** – empty, zero, None, boundaries, unicode, very large inputs, as relevant to the signature.
  20. - **Error cases** – inputs that should raise; assert the exact exception type with `pytest.raises`.
  21. 4. Isolate side effects: use `tmp_path` for files, `monkeypatch` for env vars/time, `unittest.mock` for network/DB/subprocess. Never hit the network.
  22. 5. Use `@pytest.mark.parametrize` when 3+ cases share a shape.
  23. 6. Write the file to `tests/test_<module>.py` (or the project's existing location/pattern).
  24. 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.
  25. ## Output constraints
  26. - One file, imports at top, no placeholder `pass` tests, no `assert True`.
  27. - Test names describe behaviour: `test_parse_date_rejects_empty_string`.
  28. - Expected values must be derived from the code's actual logic, never guessed.
  29. - End with a 2–4 line summary: file path, number of tests, anything marked xfail.
  30. ## Example
  31. Input: `def slugify(s: str) -> str` that lowercases, strips and replaces spaces with `-`.
  32. ```python
  33. import pytest
  34. from app.text import slugify
  35. @pytest.mark.parametrize("raw,expected", [
  36. ("Hello World", "hello-world"),
  37. (" padded ", "padded"),
  38. ("", ""),
  39. ])
  40. def test_slugify_basic(raw, expected):
  41. assert slugify(raw) == expected
  42. def test_slugify_rejects_none():
  43. with pytest.raises(AttributeError):
  44. slugify(None)
  45. ```
  46. ## Anti-patterns
  47. - Testing private helpers instead of public behaviour.
  48. - Copying the implementation into the test to compute expected values.
  49. - Snapshotting huge outputs instead of asserting the meaningful parts.
  50. - Leaving tests that only pass because of mocked-away logic.
README.md · README · 51 lines
  1. # python-test-generator — a free Claude Code skill
  2. 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.
  3. ## Install
  4. **macOS / Linux**
  5. ```bash
  6. git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git ~/.claude/skills/python-test-generator
  7. ```
  8. **Windows (PowerShell)**
  9. ```powershell
  10. git clone --depth 1 https://github.com/daillyteen3056-rgb/python-test-generator-skill.git "$env:USERPROFILE\.claude\skills\python-test-generator"
  11. ```
  12. 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`.
  13. To use it in a single project instead, clone into `.claude/skills/python-test-generator` inside that project.
  14. ## Use
  15. Just ask:
  16. - "write tests for utils.py"
  17. - "add unit tests for `parse_date`"
  18. - "generate pytest for this module"
  19. Or call it directly with `/python-test-generator`.
  20. ## What it does
  21. 1. Reads the target file and lists every public function, class and method.
  22. 2. Follows your project's existing test layout, `conftest.py` and fixtures.
  23. 3. Plans happy-path, edge and error cases for each unit and uses `pytest.raises` for exact exception types.
  24. 4. Isolates side effects with `tmp_path`, `monkeypatch` and `unittest.mock`, so it never touches the network.
  25. 5. Uses `@pytest.mark.parametrize` when 3 or more cases share a shape.
  26. 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.
  27. It will not write placeholder tests, `assert True`, or expected values copied from the implementation.
  28. ## More skills
  29. - **[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).
  30. - **[SkillNest](https://skillnest.dev)**: a searchable directory of 560+ free Claude Code skills.
  31. ## License
  32. [MIT](LICENSE). Independent project, not affiliated with or endorsed by Anthropic.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.