Generate comprehensive pytest test suites from PRD functional requirements with fixtures, parameterization, and coverage tracking...
Generate production-ready pytest test suites from PRD (Product Requirements Document) functional requirements, ensuring comprehensive test coverage for Nixtla plugins.
This skill automates the tedious process of creating test infrastructure for new plugins. It:
Key Benefits:
The script automatically:
PRD Structure Expected:
## Functional Requirements
### FR-1: Feature Name
- Requirement detail 1
- Requirement detail 2
### FR-2: Another Feature
- More requirements
Creates the following test files:
test_unit.py - Unit tests for individual functions
import pytest
from plugin_name.core import function_name
class TestFR1FeatureName:
"""Test FR-1: Feature Name"""
def test_basic_functionality(self):
"""Test basic happy path for FR-1"""
result = function_name(input_data)
assert result.success
def test_error_handling(self):
"""Test error handling for FR-1"""
with pytest.raises(ValueError):
function_name(invalid_input)
test_integration.py - Integration tests for MCP tools
import pytest
from mcp_server import ToolName
class TestMCPToolName:
"""Test MCP tool: tool_name"""
@pytest.mark.integration
def test_tool_execution(self, mock_api_client):
"""Test tool_name MCP tool end-to-end"""
result = ToolName.execute(params)
assert result["status"] == "success"
conftest.py - Shared fixtures
import pytest
@pytest.fixture
def sample_data():
"""Provide sample test data"""
return {"series": [...], "horizon": 14}
@pytest.fixture
def mock_api_client(monkeypatch):
"""Mock external API calls"""
class MockClient:
def forecast(self, **kwargs):
return {"predictions": [...]}
return MockClient()
Generated tests include appropriate markers:
@pytest.mark.unit - Fast, isolated tests@pytest.mark.integration - Tests with external dependencies@pytest.mark.slow - Long-running tests (>1 second)@pytest.mark.parametrize - Multiple input scenariosGenerates tests/COVERAGE_MATRIX.md:
# Test Coverage Matrix
| Requirement | Test File | Test Function | Status |
|-------------|-----------|---------------|--------|
| FR-1: Feature Name | test_unit.py | test_basic_functionality | ā
|
| FR-2: Another Feature | test_unit.py | test_feature_2 | ā
|
| MCP: tool_name | test_integration.py | test_tool_execution | ā
|
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=plugin_name --cov-report=html
# Run only unit tests
pytest tests/ -m unit
The script generates:
Missing PRD File:
Error: PRD not found at /path/to/PRD.md
Solution: Verify PRD path and ensure file exists
No Functional Requirements Found:
Warning: No FR-X sections found in PRD
Solution: Ensure PRD has "### FR-X: Title" format sections
Invalid Python Syntax in Generated Tests:
Error: Generated test file has syntax errors
Solution: Run black formatter on generated files
Import Errors in Generated Tests:
Error: Cannot import plugin_name module
Solution: Update import paths in generated tests to match actual module structure
python {baseDir}/scripts/generate_test_suite.py \
--prd 000-docs/000a-planned-plugins/implemented/nixtla-roi-calculator/02-PRD.md \
--output 005-plugins/nixtla-roi-calculator/tests \
--plugin-name nixtla-roi-calculator
Output:
ā Parsed PRD: Found 5 functional requirements, 4 MCP tools
ā Generated tests/test_unit.py (15 test functions)
ā Generated tests/test_integration.py (4 MCP tool tests)
ā Generated tests/conftest.py (6 fixtures)
ā Generated tests/COVERAGE_MATRIX.md
ā Generated tests/README.md
Test Coverage: 19/19 requirements (100%)
python {baseDir}/scripts/generate_test_suite.py \
--prd /path/to/PRD.md \
--output /path/to/tests \
--unit-only
python {baseDir}/scripts/generate_test_suite.py \
--prd /path/to/PRD.md \
--output /path/to/tests \
--dry-run
{baseDir}/scripts/generate_test_suite.py{baseDir}/assets/templates/pytest_template.py000-docs/000a-planned-plugins/implemented/nixtla-roi-calculator/02-PRD.md