Skip to main content
This guide covers testing practices, conventions, and patterns used in Skill Lab.

Test Organization

Test Structure

Tests are organized in the tests/ directory, mirroring the source code structure:

Fixtures

Test fixtures are organized in tests/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 in schema.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:
CLI tests should use the CliRunner from Typer, not pytest’s capsys. This ensures proper isolation and error handling.

Testing Parsers

Test parser behavior with various input formats:

Testing Trace Handlers

Test trace analysis handlers:

Pytest Configuration

The pyproject.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

Use unittest.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:
  1. Unit tests - All tests in tests/
  2. Coverage - Minimum 80% coverage required
  3. Type checking - mypy src/ in strict mode
  4. Linting - ruff check src/
  5. 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
Don’t chase 100% coverage. Focus on testing critical paths and edge cases rather than hitting arbitrary coverage numbers.