Skip to content
/

Pytest setup

Your first crewChapter 10 of 141 min read

Install pytest and write schema validation tests to catch YAML configuration errors before executing language models.


Install pytest#

Install pytest into your active virtual environment:

Terminal
(env)$ pip install pytest==9.1.1

Test the config#

Create test_config.py to validate that all required keys exist across agent and task configurations:

test_config.py
# test_config.py

from review_crew import agents_config, tasks_config


def test_every_agent_has_a_role_goal_and_backstory():
    for name, agent in agents_config.items():
        assert {"role", "goal", "backstory"} <= agent.keys(), name


def test_every_task_has_a_description_and_expected_output():
    for name, task in tasks_config.items():
        assert {"description", "expected_output"} <= task.keys(), name

These assertions evaluate in-memory dictionaries without making network requests or incurring LLM API costs.

Execute the test suite:

Terminal
(env)$ python -m pytest

test_config.py ..                                                        [100%]

======================== 2 passed, 11 warnings in 3.42s ========================

Verify your current workspace layout:

Project structure
contract-crew├── .env├── .gitignore├── config│   ├── agents.yaml│   └── tasks.yaml├── contracts│   └── acme-saas-agreement.md├── explain.py├── output│   └── review.md├── review_crew.py├── summarize.py└── test_config.py