Skip to main content
Leverage descriptive comments to auto-generate boilerplate classes, domain-specific methods, and tests in Python using GitHub Copilot. This workflow speeds up development and enforces consistency across your codebase.

Table of Contents

  1. Overview
  2. Prerequisites
  3. Generate a Python Class from Comments
  4. Extend with Domain-Specific Methods
  5. Comment-Driven Function Generation
  6. Auto-Generate Unit Tests
  7. Resources & References

Overview

Comment-driven development (CDD) lets you write plain-English comments that describe the code you need. GitHub Copilot reads these comments and generates the corresponding implementation, including:
  • Classes with type hints and validation
  • Data-processing methods
  • Standalone functions
  • pytest unit tests
CDD reduces boilerplate and keeps your focus on business logic.

Prerequisites

Before you begin, ensure the following are installed:

Generate a Python Class from Comments

Open main.py and write a high-level description of the class you want:
GitHub Copilot will trigger on typing patterns like def or class. Press Tab (or your configured shortcut) to accept the suggestion.
After accepting Copilot’s suggestion, your file should look like this:

Instantiate and Verify


Extend with Domain-Specific Methods

You can drive Copilot to add data-processing methods by writing comments in the class. For example, to analyze stock data:
Add this directly under the Employee class. Running main.py again confirms existing behavior is preserved:

Comment-Driven Function Generation

Standalone functions are just as easy. In main.py, add:
Copilot generates:

Auto-Generate Unit Tests

Create test_main.py and write test-descriptive comments:
Copilot suggests:
Run tests:

Always review generated code for edge cases and security considerations—AI suggestions may not cover every scenario.

Resources & References

Watch Video