Files
gh-basher83-lunar-claude-pl…/skills/python-uv-scripts/workflows/testing-strategies.md
2025-11-29 18:00:18 +08:00

73 lines
1.3 KiB
Markdown

# Testing Strategies for UV Scripts
> **Status**: 🚧 Placeholder - Content in development
## Overview
Strategies for testing UV single-file scripts, from inline tests to pytest integration.
## Topics to Cover
- [ ] Inline test functions
- [ ] pytest integration
- [ ] Mock and fixtures for testing
- [ ] Testing CLI applications
- [ ] API client testing with mocks
- [ ] Coverage reporting
- [ ] Test automation in CI/CD
## Quick Example
### Inline Testing
```python
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.11"
# ///
def add(a: int, b: int) -> int:
return a + b
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
print("✓ All tests passed")
if __name__ == "__main__":
# Run tests
test_add()
# Or run main application
result = add(10, 20)
print(f"Result: {result}")
```
### Pytest Integration
```python
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.11"
# dependencies = ["pytest>=7.0.0"]
# ///
"""
Run with: pytest this_script.py
"""
def multiply(a: int, b: int) -> int:
return a * b
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(-1, 5) == -5
```
## TODO
This file will be expanded to include:
- Complete testing patterns
- Mocking external dependencies
- Test organization strategies
- CI/CD integration examples
- Coverage tools and reporting