CogAgent
CogAgent copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the CogAgent project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with proper dependency management, code coverage reporting, and test organization.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith full Poetry configuration - Consolidated dependencies: Merged dependencies from
requirements.txtandapp/requirements.txt - Python version: Set to Python 3.10+ due to Gradio requirements
- Optional dependency groups: Created groups for finetune and vllm dependencies
Testing Framework
- Added testing dependencies:
pytest(^7.4.0) - Main testing frameworkpytest-cov(^4.1.0) - Coverage reportingpytest-mock(^3.11.0) - Mocking utilities
Test Configuration
-
pytest configuration in
pyproject.toml:- Test discovery patterns for
test_*.pyand*_test.py - Coverage reporting with 80% threshold
- HTML and XML coverage output formats
- Strict markers and configuration
- Custom test markers:
unit,integration,slow
- Test discovery patterns for
-
Coverage configuration:
- Source directories:
app,inference,finetune - Exclusions for test files, caches, and build artifacts
- Branch coverage enabled
- Detailed reporting options
- Source directories:
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/ # Unit tests directory
│ └── __init__.py
└── integration/ # Integration tests directory
└── __init__.py
Test Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir- Temporary directory managementmock_model_config- Model configuration mockingmock_transformers_model- Transformers model mockingmock_tokenizer- Tokenizer mockingmock_image_data- Image data for testingmock_openai_client- OpenAI client mockingmock_gradio_interface- Gradio interface mockingenv_setup- Environment variable setupmock_torch_cuda- CUDA availability mocking- And more...
Development Commands
Added Poetry script commands:
poetry run test- Run all testspoetry run tests- Alternative command (both work)
Git Configuration
Updated .gitignore with:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/, etc.) - Claude settings (
.claude/*) - Note about not ignoring
poetry.lock - Additional IDE and build artifacts
Validation
- Created
tests/test_setup_validation.pyto verify the infrastructure - Created
run_validation.pyscript for quick setup verification
Instructions for Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install --with dev -
Run tests:
poetry run test # or poetry run tests -
Run tests with specific markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests -
View coverage report:
# After running tests, open the HTML report open htmlcov/index.html
Additional Notes
- The project requires Python 3.10+ due to Gradio dependency requirements
- Optional dependency groups can be installed with:
poetry install --with finetunefor finetuning dependenciespoetry install --with vllmfor VLLM server dependencies
- The testing infrastructure is ready for immediate use - developers can start writing tests in the appropriate directories
- All test fixtures are available globally through
conftest.py - Coverage threshold is set to 80% and will fail the test run if not met
Next Steps
With this infrastructure in place, the team can:
- Start writing unit tests for individual modules
- Create integration tests for end-to-end scenarios
- Add performance benchmarks using the
slowmarker - Integrate testing into CI/CD pipelines
- Track code coverage over time