agentsclimarketplace

Python fastapi ddd testing skill

Skill iktakahiro/python-fastapi-ddd-skill/skills/python-fastapi-ddd-testing-skill

Guides unit testing for Python DDD + Onion Architecture apps (Domain Entities/Value Objects and UseCases) using pytest and repository mocks, based on the dddpy reference. Use when adding tests, choosing what to mock, or structuring test folders for a DDD FastAPI project.From its SKILL.md

Install
npx -y skills add iktakahiro/python-fastapi-ddd-skill --skill python-fastapi-ddd-testing-skill

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as Apache-2.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

1.9 KB, 321 tokens by cl100k_base, as published. Nobody here has run it

Testing DDD Layers with pytest (Domain / UseCase)

This skill focuses on unit tests for the inner layers:

  • Domain: Value Objects + Entities (pure business rules)
  • UseCase: application workflows that orchestrate Domain + Repository interfaces

It intentionally avoids full HTTP/API tests unless explicitly requested.

Test strategy (recommended)

  1. Domain tests: no mocks, assert invariants and state transitions.
  2. UseCase tests: mock repository interfaces (Mock(spec=...)), assert:
    • correct repository method calls
    • correct domain exceptions raised
    • correct entity state transitions
  3. Infrastructure/Presentation: add integration tests separately (optional).

Folder structure

Mirror the Onion layers:

tests/
  domain/{aggregate}/...
  usecase/{aggregate}/...
  infrastructure/...   # optional integration tests
  presentation/...     # optional API tests

UseCase testing pattern (dddpy-based)

Use unittest.mock.Mock(spec=RepoInterface) so typos fail fast.

from unittest.mock import Mock
import pytest

@pytest.fixture
def todo_repository_mock():
    return Mock(spec=TodoRepository)

def test_create_todo_calls_save(todo_repository_mock):
    usecase = CreateTodoUseCaseImpl(todo_repository_mock)
    title = TodoTitle("Test")

    todo = usecase.execute(title=title)

    todo_repository_mock.save.assert_called_once_with(todo)

For more examples (Value Object validation, entity lifecycle tests, and exception cases), read references/TESTING.md.

What ships with it: 2 files

3.1 KB alongside SKILL.md

agents/

references/

Gives 0 of the 12 instructions most test skills give in 321 tokens

Counted across 1,201 of the 2,096 authors here whose files we hold, read 2026-09-06

  • Write a failing test before writing codein 43 of 1201, across 36 files
  • Run the full test suitein 36 of 1201, across 35 files
  • Test only one variable per experimentin 34 of 1201, across 17 files
  • Read product marketing context before asking questionsin 34 of 1201, across 14 files
  • Mock external dependenciesin 34 of 1201, across 30 files
  • Define primary, secondary, and guardrail metricsin 33 of 1201, across 16 files
  • Pre-determine sample size before startingin 31 of 1201, across 14 files
  • Test behavior rather than implementationin 31 of 1201, across 29 files
  • Formulate a hypothesis before designing a testin 30 of 1201, across 13 files
  • Document every test hypothesis, variant, and resultin 29 of 1201, across 11 files
  • Use descriptive test function namesin 25 of 1201, across 21 files
  • Commit to the methodology without stopping earlyin 24 of 1201, across 8 files

Said here and by no other author read

  • Test domain entities without mocks
  • Assert domain invariants and state transitions
  • Mock repository interfaces in usecase tests
  • Use spec in mock objects to fail fast
  • Assert repository method calls in usecase tests
  • Assert domain exceptions in usecase tests

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.