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.tomlwith full Poetry configurationrequirements.txtandapp/requirements.txtTesting 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_*.pyand*_test.pyunit,integration,slowCoverage configuration:
app,inference,finetuneDirectory 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
.gitignorewith:.pytest_cache/,.coverage,htmlcov/, etc.).claude/*)poetry.lockValidation
tests/test_setup_validation.pyto verify the infrastructurerun_validation.pyscript 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.htmlAdditional Notes
poetry install --with finetunefor finetuning dependenciespoetry install --with vllmfor VLLM server dependenciesconftest.pyNext Steps
With this infrastructure in place, the team can:
slowmarker