agentleFS
JoseVelazcoHJoseVelazcoH/python-skills/skills/python-testing-tdd/SKILL.md

python-testing-tdd

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Trigger: write tests, pytest, TDD, red-green-refactor, fixtures, mocks, parametrize, coverage, test first. Drive Python features test-first with quality pytest patterns.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test-first development with pytest.

    line 12
  2. Very specific:

    Use parametrize only for the same check over many inputs: separate tests for distinct scenarios.

    line 25

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Testing & TDD

Test-first development with pytest. Combines the Red-Green-Refactor workflow with quality test patterns.

Activation Contract

Apply when the user writes tests, builds a feature test-first, asks about pytest/fixtures/mocks/coverage, or wants the full TDD cycle. Default to TDD: test before implementation.

Hard Rules

  • Red → Green → Refactor, in that order. Write a failing test first; write the minimal code to pass; then improve with tests green.
  • One scenario per test. Name it test_<subject>_<condition>_<expected>. Follow Arrange-Act-Assert.
  • Tests must be isolated and order-independent: no shared mutable module state.
  • Mock only external boundaries (APIs, email, payments, time, uuid, random). Use a real test database; never mock internal repositories/services or the code under test.
  • Enable branch coverage (--cov-branch); cover both sides of every conditional, not just lines.
  • Use parametrize only for the same check over many inputs: separate tests for distinct scenarios.

Decision Gates

SituationAction
New behavior requestedWrite failing test first (Red)
External dependency in unitMock it (AsyncMock/Mock(spec=...))
DB involvedReal test DB + transaction rollback fixture
Same assertion, many inputs@pytest.mark.parametrize
Distinct scenariosSeparate named tests
Async codeasyncio_mode = "auto", async fixtures

Execution Steps

  1. RED: write the smallest failing test for the next behavior; run it, confirm it fails for the right reason.
  2. GREEN: write the minimal code to pass; run, confirm green.
  3. REFACTOR: clean code and tests while green.
  4. Repeat per behavior; track phases explicitly for non-trivial features.
async def test_create_order_with_two_items_sums_total(service):
    # Arrange
    items = [{"price": 100, "qty": 2}, {"price": 50, "qty": 1}]
    # Act
    order = await service.create(items=items)
    # Assert
    assert order.total == 250

Output Contract

Return tests (and, in TDD, the minimal implementation) with clear behavior-naming, isolation via fixtures, and external-only mocking. State which phase (Red/Green/Refactor) each change belongs to.

References

  • Pair with python-clean-code and python-design-principles during Refactor.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.