starcoder
starcoder copied to clipboard
Add comprehensive Python testing infrastructure
About UnitSeeker
Hi! This PR is part of the UnitSeeker project, a human-guided initiative to help Python repositories establish testing infrastructure.
Key points:
- Human-approved: Every PR is manually approved before work begins
- Semi-automated with oversight: Created and controlled via a homegrown wrapper around Claude Code with human quality control
- Infrastructure only: This PR intentionally contains only the testing setup without actual unit tests
- Your repository, your rules: Feel free to modify, reject, or request changes - all constructive feedback is welcome
- Follow-up support: All responses and discussions are personally written, not automated
Learn more about the project and see the stats on our progress at https://unitseeker.llbbl.com/
Summary
This PR adds a comprehensive testing infrastructure to the StarCoder project, providing a foundation for writing and running tests with minimal friction.
Changes Made
Package Management
- Poetry Setup: Migrated from
requirements.txtto Poetry for modern Python dependency management - Dependency Migration: All existing dependencies from
requirements.txtpreserved inpyproject.toml - Testing Dependencies: Added
pytest,pytest-cov, andpytest-mockas development dependencies - Lock File: Generated
poetry.lockfor reproducible builds across environments
Testing Configuration
- pytest Configuration: Comprehensive pytest setup in
pyproject.tomlwith:- Test discovery patterns for files, classes, and functions
- Coverage tracking for
chat/andfinetune/packages - HTML, XML, and terminal coverage reporting
- Strict markers and config enforcement
- Custom markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - Coverage threshold placeholder (80%) ready to be enabled
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_infrastructure.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Test Fixtures
The tests/conftest.py file provides reusable fixtures for common testing scenarios:
temp_dir- Temporary directory for file operationstemp_file- Temporary test filemock_config- Mock configuration dictionarymock_tokenizer- Mock HuggingFace tokenizermock_model- Mock model for inference testingsample_text&sample_code_snippet- Sample datamock_dataset- Mock dataset for data pipeline testingmock_training_args- Mock training configurationmock_huggingface_hub- Mock HuggingFace Hub clientreset_environment- Auto-cleanup for environment variables
Validation Tests
Created test_infrastructure.py with 27 tests to validate:
- ✅ pytest is working correctly
- ✅ Python version requirements (3.8+)
- ✅ Project structure is correct
- ✅ Custom markers are registered and functional
- ✅ All fixtures work as expected
- ✅ Coverage and mocking packages are installed
- ✅ Test parametrization works
Development Commands
Two convenient shortcuts for running tests:
poetry run test # Run all tests
poetry run tests # Alternative command (both work)
Updated .gitignore
Added entries for:
- Claude Code artifacts (
.claude/) - VS Code settings (
.vscode/,*.code-workspace) - Testing artifacts already covered by default Python gitignore
Running Tests
Setup
# Install dependencies (first time only)
poetry install
# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run only unit tests
poetry run pytest -m unit
# Run only integration tests
poetry run pytest -m integration
# Run tests without coverage
poetry run pytest --no-cov
# Generate and view coverage report
poetry run pytest
open htmlcov/index.html # View HTML coverage report
Using the shortcuts
poetry run test # Runs pytest with all configured options
poetry run tests # Alternative (same as above)
Notes
Coverage Threshold
The 80% coverage threshold is currently commented out in pyproject.toml:
# Uncomment to enforce coverage threshold once actual tests are written:
# "--cov-fail-under=80",
Uncomment this line when you're ready to enforce minimum coverage requirements.
No Actual Unit Tests
This PR intentionally does not include unit tests for the codebase. The goal is to provide:
- A working testing infrastructure
- Validated configuration
- Useful fixtures and examples
- Clear documentation
Developers can immediately start writing tests without any setup overhead.
Poetry vs pip
Poetry was chosen for:
- Modern dependency resolution
- Automatic virtual environment management
- Lockfile for reproducible builds
- Built-in support for dev dependencies
- Simple script shortcuts
If you prefer to stick with requirements.txt, you can extract dependencies:
poetry export -f requirements.txt --output requirements.txt
Dependencies
All existing dependencies preserved:
tqdm==4.65.0transformers==4.28.1datasets==2.11.0huggingface-hub==0.13.4accelerate==0.18.0
Testing the Infrastructure
The infrastructure has been validated with 27 passing tests:
============================= 27 passed in 0.28s =============================
All features confirmed working:
- ✅ Test discovery and execution
- ✅ Coverage reporting (HTML, XML, terminal)
- ✅ Custom markers
- ✅ All fixtures
- ✅ Test parametrization
- ✅ Mocking capabilities
Next Steps
- Start Writing Tests: Use the fixtures in
conftest.pyas building blocks - Organize Tests: Place unit tests in
tests/unit/, integration tests intests/integration/ - Use Markers: Tag tests with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow - Enable Coverage Threshold: Uncomment
--cov-fail-under=80when ready - Customize: Modify
pyproject.tomlsettings to match your team's preferences
Questions?
Feel free to ask questions, request changes, or suggest improvements. All feedback is welcome and appreciated!