Test Organization
Test Structure
Tests are organized in thetests/ directory, mirroring the source code structure:
Fixtures
Test fixtures are organized intests/fixtures/skills/. Each subdirectory represents a complete skill with a SKILL.md file and optional supporting files.
Creating Test Fixtures
Running Tests
Basic Commands
Coverage Reports
Generate and view coverage reports:The coverage configuration in
pyproject.toml excludes common patterns like __repr__, if TYPE_CHECKING:, and if __name__ == "__main__":.Testing Patterns
Testing Static Checks
There are two patterns for testing static checks, depending on the check type:1. Schema-Based Checks (Registry Lookup)
For checks defined inschema.py using FieldRule:
2. Behavioral Checks (Direct Import)
For checks with custom implementation:Testing with Fixtures
Use pytest fixtures for common test data:Testing Error Cases
Test both success and failure paths:Testing CLI Commands
Use Typer’s testing utilities:Testing Parsers
Test parser behavior with various input formats:Testing Trace Handlers
Test trace analysis handlers:Pytest Configuration
Thepyproject.toml file contains pytest configuration:
Test Discovery
- Test files: Must be named
test_*.py - Test functions: Must be named
test_* - Test classes: Must be named
Test* - Test methods: Must be named
test_*
Writing Effective Tests
Best Practices
1
Use descriptive names
Test names should clearly describe what they test:
2
Test one thing at a time
Each test should verify a single behavior:
3
Use fixtures for common setup
Extract common setup into fixtures:
4
Test edge cases
Don’t just test the happy path:
5
Use assertions effectively
Make assertions specific and clear:
Common Patterns
Parametrized Tests
Test multiple cases with the same logic:Testing Exceptions
Test that exceptions are raised correctly:Mocking External Dependencies
Useunittest.mock for external dependencies:
Continuous Integration
Tests are automatically run on CI for:- All pull requests
- Commits to main branch
- Release tags
CI Checks
The CI pipeline runs:- Unit tests - All tests in
tests/ - Coverage - Minimum 80% coverage required
- Type checking -
mypy src/in strict mode - Linting -
ruff check src/ - Formatting -
ruff format --check src/
All CI checks must pass before a PR can be merged. Run these checks locally to catch issues early.
Debugging Tests
Using pytest Debugging Features
Using Python Debugger
Add breakpoints in test code:Test Coverage Goals
- Overall: Maintain >80% coverage
- Core modules: >90% coverage for
core/,checks/,parsers/ - CLI: >70% coverage (some paths are hard to test)
- New code: All new features must have tests