تخطَّ إلى المحتوى
TakoAPI
العودة إلى المهارات

clean-pytest

بواسطة marcoracer

CLI Utilities
404التنزيلات وفق ما يذكره clawskills.sh
0المشاهدات
لا إعجاباتسجّل الدخول للإعجاب بهذه المهارة
—لم يُقيَّم بعد
تقييمك

موجز

Write clean, maintainable pytest tests using Fake-based testing, contract testing, and dependency injection patterns.

الوصف

ما الذي تفعله هذه المهارة

Provides pytest testing patterns built around Fake classes, contract testing, and dependency injection. Targets Python projects with layered architectures where tests cover controllers, services, and repositories without hitting real external dependencies. Tests are structured using the explicit AAA pattern with composable fixtures.

Fake-based testing avoids the fragility of unittest.mock patches by using explicit in-memory implementations that are easier to read, debug, and extend without monkey-patching.

متى تستخدمها

  • Replacing unittest.mock patches with in-memory Fake classes for auth or database layers
  • Verifying MCP tool registration and argument passing through contract tests
  • Parametrizing tests to cover multiple user roles or input combinations
  • Testing rollback behavior when a downstream repository call fails
  • Composing conftest.py fixtures with injected dependencies across test files

مثال على سير العمل

الإدخال

User asks: write tests for a UserService that creates users via an auth provider and stores them in a repository

الوكيل
  1. 1

    Create FakeAuth and FakeUsersRepo classes implementing the same interface as the real dependencies

  2. 2

    Define pytest fixtures in conftest.py that return fresh Fake instances per test

  3. 3

    Write a test using AAA structure: arrange the service with injected fakes, act by calling add_user, assert on return value and fake state

  4. 4

    Add a parametrized test covering multiple email, name, and role combinations

  5. 5

    Add an error-path test that sets fake_users_repo.fail_on_upsert = True and asserts the auth user is deleted on failure

الإخراج

A passing test suite with isolated, readable tests that require no network or database connection

التثبيت

clawhub install marcoracer/clean-pytest

شغّل أمر واجهة سطر الأوامر، أو الصق النص في Claude Code أو Cursor أو Codex أو أي وكيل برمجة تستخدمه.

الروابط