feat: Set up comprehensive Python testing infrastructure with Poetry #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
pyproject.toml
with full Poetry configurationrequirements.txt
andapp/requirements.txt
Testing Framework
pytest
(^7.4.0) - Main testing frameworkpytest-cov
(^4.1.0) - Coverage reportingpytest-mock
(^3.11.0) - Mocking utilitiesTest Configuration
pytest configuration in
pyproject.toml
:test_*.py
and*_test.py
unit
,integration
,slow
Coverage configuration:
app
,inference
,finetune
Directory Structure
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 mockingDevelopment Commands
Added Poetry script commands:
poetry run test
- Run all testspoetry run tests
- Alternative command (both work)Git Configuration
Updated
.gitignore
with:.pytest_cache/
,.coverage
,htmlcov/
, etc.).claude/*
)poetry.lock
Validation
tests/test_setup_validation.py
to verify the infrastructurerun_validation.py
script for quick setup verificationInstructions for Use
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
Install dependencies:
Run tests:
Run tests with specific markers:
View coverage report:
# After running tests, open the HTML report open htmlcov/index.html
Additional Notes
poetry install --with finetune
for finetuning dependenciespoetry install --with vllm
for VLLM server dependenciesconftest.py
Next Steps
With this infrastructure in place, the team can:
slow
marker