test-crewai-project
БесплатноЗапускает вложенные скриптыНе проверенDeterministic, offline testing of CrewAI crews and flows with pytest: a stub BaseLLM (shipped in references/stub_llm.py) that drives text, structured output…
от crewAIInc★ 51 звезда на GitHubОб этом скилле
Test a CrewAI Project
How to test crews and flows deterministically, without API keys, and how to debug real runs with events and traces.
Verified against crewai 1.15.22 and 1.15.23 on 2026-10-01.
Live-tested with real LLMs on 2026-10-01.
Run crewai version first; if the major/minor differs, re-verify the version-sensitive rows with the ask-docs skill.
1. Why tests need a stub LLM
A real LLM gives different text on every run, costs money, and needs a key. Every Agent without an explicit llm resolves to gpt-4.1-mini and fails at kickoff with ValueError: OPENAI_API_KEY is required when no key is set, so a CI run with no secrets cannot even start. You cannot assert on output you cannot predict.
A stub LLM fixes the responses, so assertions are exact. It keeps every real crewai code path: prompt building, {placeholder} interpolation, task context, tool execution, guardrail retries, pydantic conversion and flow routing. It also records every call, so you can assert on the prompts crewai built. That is where most bugs show up: a missing input, a dropped context, a tool that was never listed.
Test in tiers:
| Tier | Needs | What it proves |
|---|---|---|
| Unit: stub LLM, plain pytest | nothing | wiring, prompts, routing, parsing, guardrail logic |
| Guardrail truth tables | nothing | each guardrail accepts and rejects the right outputs |
Real-model runs (crewai test, smoke kickoffs) |
provider key, money | prompt quality; mark them @pytest.mark.credentialed and run offline suites with pytest -m "not credentialed" |
2. The custom BaseLLM contract in 1.15
from crewai import BaseLLM. The only abstract method is call. crewai passes from_task, from_agent and (for structured tasks) response_model as keyword arguments, so call must accept them.
call signature |
Result | |
|---|---|---|
| Bad (the public custom-LLM docs example) | def call(self, messages, tools=None, callbacks=None, available_functions=None) |
TypeError: MyLLM.call() got an unexpected keyword argument 'from_task' at kickoff |
| Good | def call(self, messages, tools=None, callbacks=None, available_functions=None, from_task=None, from_agent=None, response_model=None, **kwargs) |
runs |
| Requirement | What happens if you skip it |
|---|---|
Accept from_task, from_agent, response_model (or **kwargs) |
TypeError at the first LLM call |
Pass a non-empty model= (e.g. MyLLM(model="my-model")) |
ValidationError at construction |
Call self._emit_call_started_event(...) / self._emit_call_completed_event(...) inside with llm_call_context(): (from crewai.llms.base_llm) |
event listeners and traces never see the LLM calls (see section 9) |
Forward only role and content if you pass messages to a provider SDK |
crewai adds cache_breakpoint: True to each message; the Anthropic API rejects it with 400 ... messages.0.cache_breakpoint: Extra inputs are not permitted |
supports_function_calling() returning False |
crewai uses the ReAct text loop for tools (Thought / Action / Action Input) |
Return a validated model instance when response_model is passed |
native providers do this; returning text also works, but see section 6 for how a guardrail then sees output.pydantic |
references/stub_llm.py implements all of this. Copy it; do not write your own unless you need to.
3. Set up the test harness
- Copy
references/stub_llm.pytotests/stub_llm.pyin the project. uv add --dev pytest, then run tests withuv run pytest.- Do not run
uv run testto mean pytest. In a scaffolded crew projecttestis a project script that runscrewai test(section 8), which calls a real model. - Add
tests/.crewai-test-storage/to.gitignore.
# tests/conftest.py
import os
import socket
from pathlib import Path
# Optional, test-only switches. The AGENTS.md that `crewai create` writes leaves
# turning observability off to the user, so ask before uncommenting them.
# Without them the socket guard below does not cover everything:
# - crewai telemetry is still sent to telemetry.crewai.com when the test process
# exits, after the guard has been undone;
# - if tracing is on (CREWAI_TRACING_ENABLED=true or tracing=True) and a CrewAI
# credential exists (CREWAI_USER_PAT, or just a saved `crewai login` on the
# machine), kickoff requests a trace grant, the guard refuses it, and the test
# fails with TraceGrantError.
# If uncommented, they must run before crewai is imported; never put them in the project's .env.
# os.environ["CREWAI_DISABLE_TELEMETRY"] = "true"
# os.environ["CREWAI_TRACING_ENABLED"] = "false"
# os.environ["OTEL_SDK_DISABLED"] = "true"
# Absolute path: crewai's SQLite files and memory store go here instead of your user data dir.
os.environ["CREWAI_STORAGE_DIR"] = str(Path(__file__).parent / ".crewai-test-storage")
import pytest
@pytest.fixture(autouse=True)
def offline(monkeypatch, tmp_path):
def refuse(*args,
Установить test-crewai-project в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл test-crewai-project?
Deterministic, offline testing of CrewAI crews and flows with pytest: a stub BaseLLM (shipped in references/stub_llm.py) that drives text, structured output and tool calls with no API key, asserting on the prompts crewai built, testing guardrails and flow routing, what `crewai test` really does, event listeners for debugging, and the exact tracing/telemetry env var values. Use when writing tests for a crewai project, mocking or stubbing the LLM, writing a custom BaseLLM, seeing `TypeError: ... call() got an unexpected keyword argument 'from_task'`, `ValueError: OPENAI_API_KEY is required` in CI, `TraceGrantError` in pytest, running `crewai test`, adding a BaseEventListener, or setting CREWAI_TRACING_ENABLED / CREWAI_DISABLE_TELEMETRY / OTEL_SDK_DISABLED.
Как установить скилл test-crewai-project?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл test-crewai-project запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic