ludo-technologies/python-best-practices/testing

Claude Code and agent skill by ludo-technologies/python-best-practices

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Python test-writing best practices covering test structure, fixtures, parametrization, and mocking with pytest. Use when writing, reviewing, or refactoring tests, adding test coverage, or working in tests directories and conftest.py.

Install

npx vskill@latest install ludo-technologies/python-best-practices/testing

SKILL.md

Python Testing

A collection of test-writing best practices for pytest. Designed for AI agents and LLMs to write readable, maintainable, and trustworthy tests.

Categories

Mocking [CRITICAL]

Mock external boundaries only, and keep mocks faithful to real interfaces.

RuleDescription
mock-boundariesMock external boundaries, not internal logic
mock-autospecUse autospec to keep mocks faithful to real signatures
mock-monkeypatchUse monkeypatch for env vars and attributes
Test Structure [HIGH]

Structure tests so failures are easy to diagnose.

RuleDescription
struct-aaa-patternStructure tests as Arrange-Act-Assert
struct-test-namingName tests after the behavior they verify
struct-one-behaviorTest one behavior per test
struct-no-logicKeep conditionals and loops out of tests
Fixtures [HIGH]

Share setup without hiding it.

RuleDescription
fixture-scopeUse the narrowest fixture scope that works
fixture-conftestPlace fixtures in the nearest conftest.py
fixture-factoryUse factory fixtures for varied test data
Parametrization [MEDIUM]

Eliminate duplicated tests without hiding cases.

RuleDescription
param-parametrizeReplace duplicated tests with parametrize
param-idsGive parametrized cases readable ids

Quick Reference

Structure Patterns
python
def test_expired_token_is_rejected() -> None:
# Arrange
token = make_token(expires_at=YESTERDAY)
# Act
result = validate(token)
# Assert
assert result.valid is False
Fixture Patterns
python
# Narrow scope by default
@pytest.fixture
def user() -> User:
return User(name="alice", email="alice@example.com")
# Factory fixture for varied data
@pytest.fixture
def make_user() -> Callable[..., User]:
def _make(name: str = "alice", active: bool = True) -> User:
return User(name=name, email=f"{name}@example.com", active=active)
return _make
Parametrize Patterns
python
@pytest.mark.parametrize(
("email", "valid"),
[
pytest.param("a@example.com", True, id="simple-address"),
pytest.param("a@sub.example.com", True, id="subdomain"),
pytest.param("no-at-sign", False, id="missing-at"),
pytest.param("", False, id="empty-string"),
],
)
def test_email_validation(email: str, valid: bool) -> None:
assert is_valid_email(email) is valid
Mocking Patterns
python
# Mock the external boundary with a faithful interface.
# `mocker` requires the pytest-mock plugin; with stdlib only,
# use unittest.mock.patch as a decorator or context manager.
def test_notifies_on_signup(mocker: MockerFixture) -> None:
send = mocker.patch("app.signup.email_client.send", autospec=True)
signup(email="alice@example.com")
send.assert_called_once_with(to="alice@example.com", template="welcome")
# monkeypatch for environment variables
def test_reads_api_key(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("API_KEY", "test-key")
assert load_config().api_key == "test-key"

See Also

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
24
Repository forks
5
7-day trend score
16

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ludo-technologies/python-best-practices/testing/badge)](https://verified-skill.com/skills/ludo-technologies/python-best-practices/testing)

Something wrong with this skill or its page? Tell us.