Update cursor rules to mandate pytest for all testing

- Add explicit pytest requirement to testing-patterns.mdc
- Update user-preferences.mdc to include pytest preference
- Modify development-workflow.mdc to reference pytest usage
- Specify that all tests must use pytest framework
- Document pytest features to use (classes, fixtures, assertions)
- Add comprehensive examples of proper pytest structure
- Include DO NOT USE section for prohibited testing approaches
- Ensure CLI integration expects pytest-compatible test files
- Make it clear that manual testing and other frameworks are not allowed
This commit is contained in:
Vijay Janapa Reddi
2025-07-10 19:32:04 -04:00
parent c5084dad27
commit 3b5ce80903
3 changed files with 116 additions and 17 deletions

View File

@@ -10,7 +10,7 @@ The main development tool is [bin/tito.py](mdc:bin/tito.py). Common commands:
# Sync module: Python source → notebook → package export
python bin/tito.py sync --module {module_name}
# Test specific module
# Test specific module (uses pytest internally)
python bin/tito.py test --module {module_name}
# Get project info and status
@@ -41,7 +41,8 @@ python bin/tito.py test --module tensor
- Updates package structure
3. **Test**: `python bin/tito.py test --module {module}`
- Runs module-specific tests from `modules/{module}/tests/`
- Runs module-specific pytest tests from `modules/{module}/tests/`
- Uses pytest framework for all test execution
- Validates exported package code
- Ensures everything works end-to-end
@@ -49,6 +50,13 @@ python bin/tito.py test --module tensor
- User prefers committing when reaching good milestones
- Clean up experimental files before committing
## Testing Requirements
- **All tests must use pytest** - No manual testing or other frameworks
- Test files must be named `test_{module}.py` and located in `modules/{module}/tests/`
- Tests should use pytest classes, fixtures, and assertions
- CLI tool uses pytest internally: `subprocess.run([sys.executable, "-m", "pytest", test_file, "-v"])`
## File Relationships
```
@@ -56,7 +64,7 @@ modules/{module}/{module}_dev.py → modules/{module}/{module}_dev.ipynb
tinytorch/core/{component}.py
modules/{module}/tests/test_{module}.py
modules/{module}/tests/test_{module}.py (pytest)
```
## Module Structure
@@ -66,10 +74,7 @@ Each module should be self-contained with:
- `{module}_dev.ipynb` - Generated notebook (auto-created)
- `README.md` - Module documentation
- `tests/` - Test directory
- `test_{module}.py` - Module tests
- `test_{module}.py` - Module tests (pytest format)
Students run and pass all tests locally within the module before using nbdev to export code to the tinytorch package and build/test the overall package.
Students run and pass all tests locally within the module before using nbdev to export code to the tinytorch package and build/test the overall package.
Students run and pass all pytest tests locally within the module before using nbdev to export code to the tinytorch package and build/test the overall package.

View File

@@ -1,6 +1,10 @@
# Testing Patterns for TinyTorch
## Testing Framework Requirement
**ALWAYS USE PYTEST** - TinyTorch uses pytest as the standard testing framework for all tests. Never use manual testing, unittest, or custom test runners. All test files must be compatible with pytest.
## Test File Structure
### Module Tests (`modules/{module}/tests/test_{module}.py`)
@@ -8,11 +12,13 @@
- Validate both student TODOs and hidden solutions
- Should work with both incomplete and complete implementations
- Import from the parent module's development file
- **Must use pytest** with proper test classes and assertions
### Package Tests (`tinytorch/tests/`)
- Test the exported package functionality
- Integration tests across components
- Production-level validation
- **Must use pytest** with comprehensive test coverage
## Test Naming Convention
@@ -27,7 +33,9 @@ tinytorch/tests/test_tensor.py
tinytorch/tests/test_autograd.py
```
## Test Structure Pattern
## Test Structure Pattern (REQUIRED)
**All tests must follow this pytest pattern:**
```python
import pytest
@@ -65,20 +73,32 @@ class TestComponentName:
pass
```
## pytest Features to Use
- **Test classes** for organizing related tests
- **pytest fixtures** for setup/teardown (e.g., `capsys`, `monkeypatch`)
- **Parametrized tests** for testing multiple inputs
- **pytest.raises()** for exception testing
- **assert statements** with descriptive messages
- **Test discovery** - pytest automatically finds test files
## Running Tests
```bash
# Test specific module
# Test specific module (recommended)
python bin/tito.py test --module tensor
# Test all modules
python bin/tito.py test --all
# Run specific test file directly
# Run specific test file directly with pytest
python -m pytest modules/tensor/tests/test_tensor.py -v
# Run from within module directory
cd modules/tensor && python -m pytest tests/ -v
# Run with coverage
python -m pytest modules/tensor/tests/ --cov=tensor_dev -v
```
## Test Categories
@@ -90,10 +110,81 @@ cd modules/tensor && python -m pytest tests/ -v
## Key Testing Principles
- **Always use pytest** - No exceptions, no manual testing
- Tests should pass with both TODO stubs and complete implementations
- Educational tests should guide student learning
- Package tests ensure production readiness
- All tests should be fast and isolated
- Use descriptive test names that explain what's being tested
- Import from module development files, not the package (for module tests)
- Use pytest fixtures for common setup/teardown operations
- Group related tests in test classes
- Use parametrized tests for multiple similar test cases
## Example Comprehensive Test Structure
```python
import pytest
from pathlib import Path
import sys
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from setup_dev import hello_tinytorch, SystemInfo, DeveloperProfile
class TestBasicFunctions:
"""Test basic module functions."""
def test_hello_tinytorch_executes(self):
"""Test function runs without error."""
hello_tinytorch()
def test_hello_tinytorch_output(self, capsys):
"""Test function produces expected output."""
hello_tinytorch()
captured = capsys.readouterr()
assert "TinyTorch" in captured.out
class TestSystemInfo:
"""Test SystemInfo class."""
def test_creation(self):
"""Test class instantiation."""
info = SystemInfo()
assert hasattr(info, 'python_version')
def test_compatibility(self):
"""Test compatibility checking."""
info = SystemInfo()
assert isinstance(info.is_compatible(), bool)
class TestFileOperations:
"""Test file-related operations."""
def test_missing_file_handling(self, monkeypatch):
"""Test graceful handling of missing files."""
# Use monkeypatch to mock file operations
pass
```
## DO NOT USE
- Manual test runners (custom functions that execute tests)
- unittest framework
- Simple assert statements without pytest structure
- Print-based testing
- Custom test discovery mechanisms
- Any testing approach that doesn't integrate with pytest
## Integration with TinyTorch CLI
The `tito.py` CLI tool expects pytest-compatible test files and uses pytest internally:
```python
# In bin/tito.py
result = subprocess.run([sys.executable, "-m", "pytest", test_file, "-v"])
```
This ensures all tests run through pytest with consistent output and reporting.

View File

@@ -1,7 +1,3 @@
---
alwaysApply: true
description: User preferences and conventions for the TinyTorch educational framework.
---
# User Preferences and Conventions
@@ -11,6 +7,7 @@ description: User preferences and conventions for the TinyTorch educational fram
- **Commit frequency**: Check code into repo at good milestone stages
- **README focus**: Keep main project README focused on overarching goals, not module details
- **Component terminology**: Call code components 'modules' instead of 'parts'
- **Testing framework**: Always use pytest for all tests - no manual testing or other frameworks
## Educational Workflow
@@ -31,9 +28,15 @@ description: User preferences and conventions for the TinyTorch educational fram
- **Educational directives**: Use `#| hide` for instructor solutions, visible sections for student work
- **Package structure**: Code exports from `modules/` to `tinytorch/` package
These preferences ensure consistency across the TinyTorch educational framework and smooth development workflow.
## Testing Standards
- **Educational directives**: Use `#| hide` for instructor solutions, visible sections for student work
- **pytest only**: All tests must use pytest framework with proper test classes
- **Comprehensive coverage**: Tests should cover functionality, edge cases, and integration
- **Professional structure**: Use test classes, fixtures, and descriptive test names
- **CLI integration**: Tests must be compatible with `python bin/tito.py test --module {name}`
These preferences ensure consistency across the TinyTorch educational framework and smooth development workflow.
- **Package structure**: Code exports from `modules/` to `tinytorch/` package
These preferences ensure consistency across the TinyTorch educational framework and smooth development workflow.