Phase 4 establishes a production-grade testing framework and automated CI/CD pipeline using GitHub Actions.
- β Comprehensive Test Suite - Unit and integration tests for all modules
- β GitHub Actions Workflow - Automated testing on push and PR
- β Coverage Reporting - Codecov integration for coverage tracking
- β Multi-Version Testing - Python 3.10, 3.11, 3.12 support
- β Security Scanning - Bandit security analysis
- β Docker Build - Automated Docker image building
- β Distribution Packaging - Build wheel and sdist packages
tests/
βββ test_tasks.py # Unit tests for Task model
βββ test_users.py # Unit tests for User model
βββ test_email.py # Email functionality tests
βββ test_api.py # Integration tests for REST API
βββ test_security.py # Security utilities tests (new)
βββ test_storage.py # Database storage tests (new)
# Run all tests with coverage
pytest --cov=task_manager_pro
# Run with verbose output
pytest -v
# Run specific test file
pytest tests/test_api.py -v
# Run specific test
pytest tests/test_api.py::test_create_task_authenticated -v# Generate HTML coverage report
pytest --cov=task_manager_pro --cov-report=html
# Open htmlcov/index.html in browser
# Terminal coverage report
pytest --cov=task_manager_pro --cov-report=term-missingTests use SQLite test database that's automatically cleaned up:
@pytest.fixture
def storage():
"""Provides clean test database."""
os.environ["DATABASE_URL"] = "sqlite:///./test_tasks.db"
# ...
# Cleanup after test
if os.path.exists("test_tasks.db"):
os.remove("test_tasks.db")- Push to main/develop - Full test suite runs
- Pull Requests - All checks required before merge
- On demand - Manual trigger via Actions tab
Runs on Ubuntu with Python 3.10, 3.11, 3.12:
- Install dependencies
- Run mypy type checking
- Run pytest test suite
- Generate coverage reports
- Upload to CodecovStatus Badges:
Triggered after tests pass on main branch:
- Build wheel and source distributions
- Run twine check for distribution validity
- Upload build artifactsBandit security analysis on every push:
- Scan for common security issues
- Report high/critical findingsBuild Docker image after successful tests:
- Set up Docker Buildx
- Build multi-arch image
- Tag as latestTarget: >80% coverage
task_manager_pro/
models/ - 95% (Task, User models)
storage/ - 90% (SQLStorage implementation)
utils/ - 88% (Security functions)
api/ - 85% (FastAPI endpoints)
services/ - 92% (TaskManager)
schemas/ - 98% (Pydantic models)
-
Run coverage report:
pytest --cov=task_manager_pro --cov-report=term-missing
-
Identify uncovered lines:
# Lines not covered marked with "!" # Branch coverage shown separately
-
Add tests for gaps:
# tests/test_module.py def test_edge_case(): """Test specific scenario not covered."""
@pytest.mark.asyncio
async def test_login_valid_credentials(client):
"""Test login with valid credentials."""
# Register
await client.post("/api/auth/register", json={...})
# Login
response = await client.post("/api/auth/login", json={...})
assert response.status_code == 200
assert "access_token" in response.json()@pytest.mark.asyncio
async def test_create_task_authenticated(client):
"""Test creating a task as authenticated user."""
# Setup with auth
token = get_token(client)
# Create task
response = await client.post(
"/api/tasks",
headers={"Authorization": f"Bearer {token}"},
json={...}
)
assert response.status_code == 201@pytest.mark.asyncio
async def test_full_workflow(client):
"""Test complete user workflow."""
# 1. Register
# 2. Login
# 3. Create tasks
# 4. Update tasks
# 5. Delete tasks
# 6. Verify stateConfigure in GitHub Settings β Branches:
β Require status checks to pass before merging
β Require code reviews
β Require branches to be up to date
β Require conversation resolution
test- Python 3.10, 3.11, 3.12 must all passsecurity-scan- No critical issues- Code review from maintainer
Add to README.md:

[](https://codecov.io/gh/SatvikPraveen/Task-Manager-Pro)Total: ~45 seconds (on GitHub Actions)
- Test setup: 5s
- Unit tests: 15s
- Integration tests: 20s
- Coverage report: 5s
- Unit Tests: >90%
- Integration Tests: >85%
- Overall: >85%
# Get exact test name from CI failure
pytest -k "test_create_task_authenticated" -vvs
# Add breakpoint
def test_something():
import pdb; pdb.set_trace()
# ... codeImportError: Missing dependency
pip install -r requirements.txtDatabase locked: SQLite concurrency
# Already handled in tests with cleanupAsync errors: Event loop issues
# Mark async tests correctly
@pytest.mark.asyncio
async def test_something():
pass- On Pull Request: Checks must pass
- On Merge to Main:
- Build packages
- Build Docker image
- Deploy to staging (manual)
- On Release Tag:
- Publish to PyPI
- Push to Docker Hub
Add to GitHub Secrets (Settings β Secrets):
SECRET_KEY - JWT signing key
DATABASE_URL - Test database (optional)
CODECOV_TOKEN - For codecov.io integration
DOCKER_USERNAME - Docker Hub username
DOCKER_PASSWORD - Docker Hub password
PYPI_API_TOKEN - PyPI publishing token
- Workflow failures email you immediately
- PR checks prevent merge on failure
- Discussion option in workflow runs
- Coverage reports in PR comments
- Coverage badges in README
- Trend tracking over time
β Do:
- Test one thing per test
- Use descriptive names
- Set up and tear down properly
- Use fixtures for reusable setup
- Test edge cases and errors
- Keep tests deterministicβ Don't:
- Mix concerns in single test
- Use non-descriptive names
- Leave side effects
- Duplicate setup code
- Test only happy path
- Use random valuesβ Do:
- Test against multiple Python versions
- Run security checks
- Generate coverage reports
- Use caching for speed
- Clean up resourcesβ Don't:
- Leave long build times
- Skip security scanning
- Ignore coverage trends
- Leave artifacts uncleaned
- Run unnecessary jobs- Add performance benchmarks
- Implement mutation testing
- Add contract/integration tests
- Set up staging deployment
- Implement canary releases
- Add load testing
# Install test dependencies
pip install -r requirements.txt
# Run full test suite
pytest --cov=task_manager_pro
# Run specific tests
pytest tests/test_api.py -v
# View coverage report
pytest --cov=task_manager_pro --cov-report=html