Testing
This page covers how to run tests, check code quality, and work with the existing test infrastructure in Iris.
Running Tests
Iris uses pytest for testing. Run the full test suite from the iris/ directory:
poetry run pytest
To run with verbose output:
poetry run pytest -v
To run a specific test file:
poetry run pytest tests/test_session_title_generation_pipeline.py -v
Code Coverage
Generate a coverage report:
poetry run coverage run -m pytest # Run tests with coverage tracking
poetry run coverage html # Generate HTML report in htmlcov/
poetry run coverage report # Print summary to terminal
Coverage is configured in pyproject.toml:
[tool.coverage.run]
branch = true
source = ["src"]
dynamic_context = "test_function"
[tool.coverage.report]
show_missing = true
Test Structure
The test directory currently has minimal coverage:
tests/
├── __init__.py
├── test_dummy.py # Basic smoke test
└── test_session_title_generation_pipeline.py # Session title pipeline tests
Test coverage is an area for improvement. When adding new features, please add corresponding tests.
Linting and Code Quality
Iris uses several tools for code quality, configured in pyproject.toml and enforced via pre-commit hooks.
Black (Code Formatter)
Black enforces consistent code formatting:
poetry run black src/ tests/
To check without modifying files:
poetry run black --check src/ tests/
isort (Import Sorter)
isort sorts and organizes imports:
poetry run isort src/ tests/
Configuration in pyproject.toml:
[tool.isort]
profile = "black"
multi_line_output = 3
The profile = "black" setting ensures isort's output is compatible with Black's formatting.
Pylint (Static Analysis)
Pylint catches bugs, enforces coding standards, and detects code smells:
poetry run pylint src/iris/
Additional Tools
| Tool | Purpose | Command |
|---|---|---|
| mypy | Static type checking | poetry run mypy src/ |
| bandit | Security linting | poetry run bandit -r src/ -x tests/ |
| yamllint | YAML file linting | poetry run yamllint *.yml |
| autoflake | Remove unused imports | poetry run autoflake --check src/ |
| detect-secrets | Prevent secrets from being committed | See below |
Detect Secrets
Scan all tracked files for accidentally committed secrets:
git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
To update the baseline with current (known/accepted) secrets:
git ls-files -z | xargs -0 detect-secrets scan --baseline .secrets.baseline
Pre-commit Hooks
The pre-commit framework runs all quality checks automatically before each commit. Install hooks from the monorepo root:
cd .. # from iris/ to edutelligence/
pre-commit install
To run all hooks manually on all files:
pre-commit run --all-files
This executes Black, isort, Pylint, detect-secrets, and other configured hooks. Pre-commit configuration is defined in .pre-commit-config.yaml at the monorepo root.
Writing New Tests
When adding tests:
- Place test files in the
tests/directory. - Name test files with the
test_prefix (e.g.,test_my_pipeline.py). - Name test functions with the
test_prefix. - Use pytest fixtures for shared setup.
Example Test
from iris.pipeline.session_title_generation_pipeline import (
SessionTitleGenerationPipeline,
)
def test_session_title_generation():
"""Test that session title generation produces a non-empty result."""
pipeline = SessionTitleGenerationPipeline()
result = pipeline(
current_session_title="",
recent_messages=["User: How do I use sorting?", "Assistant: Here's how..."],
user_language="en",
)
assert result is not None
Since Iris relies heavily on external services (LLMs, Weaviate), consider mocking these dependencies in unit tests. Use unittest.mock.patch or pytest's monkeypatch fixture to replace LLM calls and database operations.