一键导入
sybil
Use Sybil for testing code examples in documentation and docstrings. Covers pytest integration, parsers, skip directives, and namespace management.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use Sybil for testing code examples in documentation and docstrings. Covers pytest integration, parsers, skip directives, and namespace management.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
This skill should be used when the user asks to "define a feature", "create a BaseFeature class", "track feature versions", "set up metadata store", "field-level lineage", "FieldSpec", "FeatureDep", "run metaxy CLI", "metaxy migrations", "metaxy lock", "lock features", "external features", "multi-environment", "monorepo features", "enable Map datatype", "enable_map_datatype", or needs guidance on metaxy feature definitions, versioning, metadata stores, CLI commands, testing patterns, feature locking, Map datatype configuration, or multi-environment configuration.
This skill should be used when the user asks to "add a tach module", "configure tach layers", "define module boundaries", "set up interfaces", "run tach check", "check module boundaries", "tach sync", "tach show", "deprecate a dependency", "tach-ignore", "unchecked modules", "tach test", "skip tests with tach", "configure tach.toml", "source roots", "forbid circular dependencies", "enforce module boundaries", "set up architectural layers", or "tach init".
Effectively use Narwhals to write dataframe-agnostic code that works seamlessly across multiple Python dataframe libraries. Write correct type annotations for code using Narwhals.
Use syrupy for pytest snapshot testing to ensure the immutability of computed results, manage snapshots, customize serialization, and handle complex data structures with built-in matchers and filters.
Write YAML front matter for documentation pages with appropriate titles and descriptions for social cards.
Self-reflect on the current session to identify mistakes and propose improvements to .claude configuration (CLAUDE.md, hooks, skills).
| name | sybil |
| description | Use Sybil for testing code examples in documentation and docstrings. Covers pytest integration, parsers, skip directives, and namespace management. |
Sybil validates code examples embedded in documentation and docstrings by parsing and executing them as part of normal test runs.
Official Documentation: https://sybil.readthedocs.io/en/latest/
pip install sybil[pytest]
Configure in conftest.py. See pytest integration docs.
from sybil import Sybil
from sybil.parsers.markdown.codeblock import PythonCodeBlockParser
from sybil.parsers.markdown.skip import SkipParser
pytest_collect_file = Sybil(
parsers=[
SkipParser(),
PythonCodeBlockParser(),
],
patterns=["*.md", "**/*.py"],
).pytest()
See API reference.
| Parameter | Description |
|---|---|
parsers | Sequence of parser callables |
patterns | File glob patterns to include (e.g., ["*.md", "src/**/*.py"]) |
excludes | File glob patterns to exclude |
setup | Callable receiving namespace dict, called before each document |
teardown | Callable receiving namespace dict, called after each document |
fixtures | List of pytest fixture names to inject into namespace |
document_types | Map file extensions to Document classes |
See API reference.
PythonDocument: Import .py file as module, names available in namespacePythonDocStringDocument: Parse only docstrings from .py filesfrom sybil.document import PythonDocStringDocument
pytest_collect_file = Sybil(
parsers=[...],
patterns=["src/**/*.py"],
document_types={".py": PythonDocStringDocument},
).pytest()
import pytest
from sybil import Sybil
@pytest.fixture
def my_fixture():
return {"key": "value"}
pytest_collect_file = Sybil(
parsers=[...],
patterns=["*.md"],
fixtures=["my_fixture"], # Available in document namespace
).pytest()
def sybil_setup(namespace):
namespace["helper"] = lambda x: x * 2
def sybil_teardown(namespace):
pass # Cleanup if needed
pytest_collect_file = Sybil(
parsers=[...],
setup=sybil_setup,
teardown=sybil_teardown,
).pytest()
Add to pyproject.toml to prevent conflicts:
[tool.pytest.ini_options]
addopts = "-p no:doctest"
from sybil.parsers.markdown.codeblock import PythonCodeBlockParser, CodeBlockParser
from sybil.parsers.markdown.skip import SkipParser
from sybil.parsers.markdown.clear import ClearNamespaceParser
See skip directive docs.
SkipParser must come before other parsers to handle skip directives.
<!-- skip: next -->
```python
# This example is skipped
```
# Skipped and reported as skipped test with reason
# Multiple examples
# All skipped
# Conditionally skipped based on namespace variable
## Invisible Code Blocks
Setup code that doesn't render in documentation. See [invisible code blocks docs](https://sybil.readthedocs.io/en/latest/markdown.html#invisible-code-blocks).
```markdown
<!-- invisible-code-block: python
setup_var = "hidden setup"
-->
Reset the document namespace for isolation. See clear namespace docs.
<!-- clear-namespace -->
See evaluators API.
from sybil.parsers.markdown.codeblock import CodeBlockParser
from sybil.evaluators.python import PythonEvaluator
# Custom evaluator with future imports
evaluator = PythonEvaluator(future_imports=["annotations"])
parser = CodeBlockParser(language="python", evaluator=evaluator)
Sybil tests are collected like regular pytest tests. To run only Sybil tests:
# Run tests from specific directory containing documented code
pytest src/mypackage/ -v
# Exclude regular tests, only run documentation examples
pytest docs/ -v
To exclude Sybil tests from regular test runs, use pytest's --ignore flag or configure addopts in pyproject.toml.
"""Sybil configuration for docstring testing."""
from sybil import Sybil
from sybil.document import PythonDocStringDocument
from sybil.evaluators.python import PythonEvaluator
from sybil.parsers.markdown.codeblock import CodeBlockParser
from sybil.parsers.markdown.skip import SkipParser
import mypackage
def sybil_setup(namespace):
"""Pre-populate namespace for all examples."""
namespace["pkg"] = mypackage
def sybil_teardown(namespace):
"""Cleanup after document."""
pass
pytest_collect_file = Sybil(
parsers=[
SkipParser(),
CodeBlockParser(language="python", evaluator=PythonEvaluator()),
CodeBlockParser(language="py", evaluator=PythonEvaluator()),
],
patterns=["src/mypackage/**/*.py"],
document_types={".py": PythonDocStringDocument},
setup=sybil_setup,
teardown=sybil_teardown,
excludes=[
"**/tests/**",
"**/_internal/**",
],
).pytest()