Testing ModuFlow
This document provides information on how to run and write tests for the ModuFlow project.
Running Tests
ModuFlow uses pytest for testing. You can run the tests with:
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run tests with coverage report
pytest --cov=moduflow
# Run tests in a specific file
pytest tests/test_core.py
# Run a specific test
pytest tests/test_core.py::TestConfigManager::test_init_config
Test Structure
Tests are organized in the tests/ directory, mirroring the main package structure:
test_cli.py- Tests for CLI functionalitytest_core.py- Tests for core functionalitytest_handlers.py- Tests for handlerstest_compilers.py- Tests for compilerstest_utils.py- Tests for utilities
Writing Tests
When adding new features, please add corresponding tests. Tests should:
Test each function’s main functionality
Include tests for edge cases and error handling
Use proper setup and teardown
Be isolated from each other (no dependencies between tests)
Example Test Structure
import unittest
from moduflow.core.config import ConfigManager
class TestConfigManager(unittest.TestCase):
"""Tests for ConfigManager."""
def setUp(self):
"""Set up test environment."""
# Create test resources
pass
def tearDown(self):
"""Clean up test environment."""
# Clean up test resources
pass
def test_some_functionality(self):
"""Test description here."""
# Arrange
manager = ConfigManager()
# Act
result = manager.some_method()
# Assert
self.assertEqual(result, expected_value)
Integration with CI/CD
Tests are automatically run in GitHub Actions:
Tests run on every push to any branch
Tests run when a pull request is opened/updated
Tests must pass before a pull request can be merged
Tests run on multiple Python versions (3.7, 3.8, 3.9, 3.10)
Adding More Tests
Currently, the basic tests are set up for the core functionality. As you develop other modules, please add tests for:
CLI Commands - Test each command with various inputs
Handlers - Test file, YAML, and section handling
Compilers - Test compilation of sections and projects
Prompts - Test generation of prompts
Utils - Test utility functions
Test Coverage
Aim for at least 80% test coverage for all modules. You can check coverage with:
pytest --cov=moduflow --cov-report=term-missing