Token导航 LogoToken导航

Agent Skill · 研究检索

dj-pytest(DJ pytest 搜索)

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。它适合让 Agent 阅读 Python 代码、定位测试问题、整理运行命令、生成脚本或分析数据处理逻辑。使用时需要确认项目虚拟环境、依赖版本和测试入口;涉及执行脚本、读写文件、访问数据库或调用外部 API 时,应先明确运行目录和输入输出范围,避免误改生产数据。

dj-pytest 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 72,083。

总安装 190周安装 8GitHub Stars 101下载 67核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dj-pytest(DJ pytest 搜索)
来源仓库:https://github.com/dvf/opinionated-django
仓库路径:skills/dj-pytest
安装命令:
npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。适合在 Codex、Claude、Cursor、Gemini CLI 中阅读 Python 代码、定位测试问题、整理运行命令或生成脚本。使用时需确认项目虚拟环境、依赖版本和测试入口,避免误改生产数据。

安装方式:github,通过 npx skills add 命令添加。涉及执行脚本或访问数据库时,应明确运行目录和输入输出范围。

来源仓库内路径:skills/dj-pytest

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

dj-pytest 怎么安装?

在终端执行 npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

dj-pytest 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

dj-pytest 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

dj-pytest 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

dj-pytest 用的人多吗?

公开数据是累计安装 190 次,近一周安装 8 次,下载 67 次,GitHub 101 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

dj-pytest 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
dj-pytest

DJ pytest 搜索 · 本页

190101需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Pytest for op-django

Testing in this project is layered the same way the code is. Each layer has its own rules, its own fixtures, and its own performance characteristics. The goal is to keep the fast tests fast — service tests should never touch a database — and to isolate the slow tests at the edges.

The Three Layers

FileWhat it coversDB?Speed
test_repo.pyORM ↔ DTO conversion, prefetches, transactions, ID prefixes✅ realslow
test_service.pyBusiness logic, validation, orchestration❌ mockedfast
test_api.pyHTTP integration — request → view → service → repo✅ realslow

Service tests are the most valuable layer and should outnumber the others. If a service test needs @pytest.mark.django_db, something has leaked — find the ORM call and push it into a repository.

Dependencies

uv add --dev pytest pytest-django pytest-celery freezegun pytest-mock
  • pytest-django — the django_db marker, client fixture, settings integration.
  • pytest-celery — lets you run Celery tasks eagerly inside tests (critical for reliable-signal receivers).
  • freezegun — freezes datetime.now(), time.time(), and friends. Required for any logic that touches timestamps, TTLs, scheduled work, or ULIDs whose sort order matters to the test.
  • pytest-mock — the mocker fixture (a thin wrapper around unittest.mock with autouse cleanup).

Configuration

Add to pyproject.toml:

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "project.settings"
python_files = ["test_*.py"]
pythonpath = ["src"]
addopts = [
    "-ra",
    "--strict-markers",
    "--strict-config",
]
markers = [
    "slow: deselect with '-m \"not slow\"'",
]

Notes:

  • pythonpath = ["src"] is what lets from project.services import get resolve without an editable install.
  • --strict-markers catches typos in @pytest.mark.xxx. --strict-config does the same for the config file.
  • Keep the markers list small and meaningful — one or two genuine custom markers maximum.

Celery in Tests

Reliable signals enqueue Celery tasks. For receivers to execute in-process during tests, set Celery to eager mode. Add to src/project/settings.py (or a test-only settings module):

if "pytest" in sys.modules:
    CELERY_TASK_ALWAYS_EAGER = True
    CELERY_TASK_EAGER_PROPAGATES = True

With eager mode on, send_reliable() still goes through transaction.on_commit, so tests that exercise reliable signals must run inside @pytest.mark.django_db with transaction=True so on_commit actually fires. More on that below.

tests/conftest.py

A single project-level conftest.py holds the fixtures every test layer can pull from. Keep it small and generic — feature-specific fixtures go in per-app conftest.py files.

from __future__ import annotations

from decimal import Decimal
from typing import Any
from unittest.mock import MagicMock

import pytest
from freezegun import freeze_time

from products.dtos.product import ProductDTO

# ---- time --------------------------------------------------------------

@pytest.fixture
def frozen_time():
    """Freeze time at a deterministic instant. Use when tests care about now()."""
    with freeze_time("2026-01-01T00:00:00Z") as frozen:
        yield frozen

# ---- svcs --------------------------------------------------------------

@pytest.fixture
def override_service():
    """
    Swap a real service factory for a fake for the duration of a test.

    Usage:
        def test_something(override_service):
            fake = MagicMock(spec=ProductService)
            fake.list_products.return_value = []
            override_service(ProductService, fake)
            ...
    """
    from project.services import registry

    originals: dict[type, Any] = {}

    def _override(service_type: type, fake: Any) -> None:
        originals.setdefault(service_type, registry._factories.get(service_type))
        registry.register_factory(service_type, lambda _container: fake)

    yield _override

    for service_type, original in originals.items():
        if original is not None:
            registry._factories[service_type] = original

# ---- DTO builders ------------------------------------------------------

@pytest.fixture
def make_product_dto():
    """Build a ProductDTO with sensible defaults; override anything via kwargs."""

    def _build(**overrides: Any) -> ProductDTO:
        fields: dict[str, Any] = {
            "id": "prd_01jq3v8f6a7b2c8d9e0f1g2h3j",
            "name": "Widget",
            "price": Decimal("9.99"),
            "stock": 5,
        }
        fields.update(overrides)
        return ProductDTO(**fields)

    return _build

# ---- repository mocks --------------------------------------------------

@pytest.fixture
def mock_product_repo(make_product_dto):
    """A MagicMock spec'd against ProductRepository, pre-loaded with a DTO."""
    from products.repositories.product import ProductRepository

    repo = MagicMock(spec=ProductRepository)
    repo.create.return_value = make_product_dto()
    repo.get_by_id.return_value = make_product_dto()
    repo.list_all.return_value = [make_product_dto()]
    return repo

A few patterns worth calling out:

  • Factories over fixtures for data. make_product_dto() is more flexible than a product_dto fixture because tests can ask for make_product_dto(stock=0) instead of mutating a shared instance.
  • spec= on mocks. Always pass spec=SomeRepository to MagicMock — it makes the mock fail fast on attribute typos and keeps tests honest when the real class changes.
  • override_service lets API tests substitute a fake service without monkey-patching imports. The yield/restore dance is important so a test's override doesn't bleed into the next one.

Writing Each Layer

test_repo.py — Real database

import pytest
from decimal import Decimal

from products.repositories.product import ProductRepository
from products.dtos.product import ProductDTO

@pytest.mark.django_db
def test_create_returns_dto_with_prefixed_id():
    repo = ProductRepository()

    dto = repo.create(name="Widget", price=Decimal("9.99"), stock=5)

    assert isinstance(dto, ProductDTO)
    assert dto.id.startswith("prd_")
    assert dto.price == Decimal("9.99")

@pytest.mark.django_db
def test_get_by_id_round_trips():
    repo = ProductRepository()
    created = repo.create(name="Widget", price=Decimal("9.99"), stock=5)

    fetched = repo.get_by_id(created.id)

    assert fetched == created
  • Always assert on the prefix — it's a cheap proof the ULID generator is wired up.
  • Assert on the DTO type at least once per repo — catches a repo accidentally returning an ORM instance.
  • Use @pytest.mark.django_db(transaction=True) only when you need to exercise transaction.on_commit behavior (i.e. reliable-signal tests). It's significantly slower than the default.

test_service.py — No database

from decimal import Decimal

import pytest

from products.services.product import ProductService

def test_create_product_delegates_to_repo(mock_product_repo, make_product_dto):
    mock_product_repo.create.return_value = make_product_dto(name="Gadget")

    service = ProductService(mock_product_repo)
    result = service.create_product(name="Gadget", price=Decimal("9.99"), stock=5)

    assert result.name == "Gadget"
    mock_product_repo.create.assert_called_once_with(
        name="Gadget", price=Decimal("9.99"), stock=5
    )

def test_create_order_rejects_insufficient_stock(make_product_dto):
    order_repo = MagicMock()
    product_repo = MagicMock()
    product_repo.get_by_id.return_value = make_product_dto(stock=1)

    service = OrderService(order_repo, product_repo)

    with pytest.raises(ValueError, match="Insufficient stock"):
        service.create_order(items=[{"product_id": "prd_fake", "quantity": 5}])

    order_repo.create.assert_not_called()
  • No @pytest.mark.django_db. If you reach for it in a service test, you've found a leak.
  • Assert on both the return value and the repo calls. The return value proves the outcome; the call assertion proves the service routed the work correctly and didn't swallow arguments.
  • Use assert_not_called() on negative paths — it's the cleanest way to prove that a validation error short-circuited a write.

test_api.py — HTTP integration

import pytest

@pytest.mark.django_db
def test_create_product(client):
    response = client.post(
        "/api/products/",
        data={"name": "Widget", "price": "9.99", "stock": 5},
        content_type="application/json",
    )

    assert response.status_code == 201
    body = response.json()
    assert body["id"].startswith("prd_")
    assert body["name"] == "Widget"

@pytest.mark.django_db
def test_list_products_empty(client):
    response = client.get("/api/products/")

    assert response.status_code == 200
    assert response.json() == []
  • client is provided by pytest-django.
  • Prefer asserting on shape and a prefix over a full dict comparison — test becomes resilient to added optional fields.
  • If a route is just a passthrough to a service, one happy-path test is enough — the service tests cover the business logic, the repo tests cover persistence, and this test proves the wiring.
Testing the exception handler

Services raise plain Python exceptions (ValueError, LookupError, PermissionError); the central exception handler in src/project/api/__init__.py maps them to HTTP responses (400, 404, 403) with a {"detail": "..."} body. API tests are the layer that proves the round-trip — assert on the status code and the JSON body, not on the raised exception.

@pytest.mark.django_db
def test_create_order_rejects_insufficient_stock(client):
    # Create a product with only 1 in stock.
    product_resp = client.post(
        "/products/",
        data={"name": "Limited", "price": "5.00", "stock": 1},
        content_type="application/json",
    )
    product_id = product_resp.json()["id"]

    response = client.post(
        "/orders/",
        data={"items": [{"product_id": product_id, "quantity": 10}]},
        content_type="application/json",
    )

    assert response.status_code == 400
    assert "Insufficient stock" in response.json()["detail"]

The equivalent test_service.py test should assert the raw exception (with pytest.raises(ValueError, match="Insufficient stock"):) rather than a status code — the service test doesn't go through the API, so it never sees the HTTP mapping. Layering matters: service tests prove the exception is raised, API tests prove the exception handler maps it correctly.

Reliable-signal tests

Receivers run via Celery. With CELERY_TASK_ALWAYS_EAGER, they execute in-process, but transaction.on_commit only fires when the transaction actually commits — which means you need the transaction=True flavor of the marker:

import pytest

from orders.receivers import on_order_created
from orders.services.order import OrderService

@pytest.mark.django_db(transaction=True)
def test_order_created_triggers_receiver(mocker, make_product_dto):
    spy = mocker.patch("orders.receivers.on_order_created", wraps=on_order_created)
    # ...build real repos, call service.create_order(...), then:
    spy.assert_called_once()

def test_receiver_is_idempotent(mocker):
    send_email = mocker.patch("orders.receivers.send_order_confirmation")

    on_order_created(order_id="ord_fake")
    on_order_created(order_id="ord_fake")

    assert send_email.call_count == 1  # or whatever idempotency you've implemented

The second test is the one that matters — every receiver needs an explicit "called twice, ran once" test. At-least-once delivery is non-negotiable and so is the test that proves you respected it.

freezegun

Use @freeze_time (or the frozen_time fixture) for any test that asserts on timestamps, TTLs, scheduling windows, or otherwise time-sensitive logic.

from freezegun import freeze_time

@freeze_time("2026-01-15T12:00:00Z")
def test_expires_at_is_24h_from_now(make_product_dto):
    service = SubscriptionService(MagicMock())
    dto = service.start_trial(user_id="usr_fake")

    assert dto.expires_at.isoformat() == "2026-01-16T12:00:00+00:00"
  • Prefer freezing at the test function level, not globally — it makes the time dependency visible in the test body.
  • Freeze at a meaningful instant (e.g. a date relevant to the assertion), not at "2020-01-01". Future-you will thank you.
  • Do not freeze time in repository tests unless the test specifically asserts on a timestamp. Frozen time interacts poorly with ULID generation, which encodes the current time into the ID.

Common Mistakes

  • Reaching for @pytest.mark.django_db in a service test. The service has an ORM import hiding in it. Fix the service, not the test.
  • Using a fixture that returns a shared mutable object. Tests mutate it, then order-dependence bites you. Use factories (make_*) instead.
  • Asserting on response.json() == {...} with the full dict. Too brittle. Assert on the fields you care about plus an ID prefix.
  • Forgetting transaction=True on reliable-signal tests. on_commit won't fire, the receiver won't run, and the test silently passes without exercising anything.
  • Testing Django internals. Don't write a test that boils down to "does .filter() work?" — trust the framework and test your code.
  • Missing the idempotency test. Every reliable-signal receiver needs a test that proves calling it twice is safe.
  • Asserting on a status code for a business-rule violation in a test_service.py file. Service tests should use pytest.raises; only test_api.py round-trips through the exception handler.

Verify

uv run pytest
uv run pytest -m "not slow"       # fast loop for iterating
uv run pytest tests/orders/        # one app
uv run pytest --lf                 # re-run last failures only
  • All tests must pass before reporting done.
  • Service tests should make up the majority of the suite — if test_repo.py and test_api.py are outnumbering test_service.py, business logic is in the wrong layer.

平台分布

Codex

33.55%
按下载量换算22

Claude

32.32%
按下载量换算22

Cursor

17.59%
按下载量换算12

Gemini CLI

9.08%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills