TextGAN-PyTorch
TextGAN-PyTorch copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the GAN models project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for developers to immediately start writing unit and integration tests.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith complete Poetry setup - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Updated NumPy: Upgraded from numpy 1.14.5 to ^1.21.0 for compatibility
Testing Framework
- pytest: Main testing framework with full configuration
- pytest-cov: Coverage reporting with HTML and XML output formats
- pytest-mock: Mocking utilities for test isolation
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Testing Configuration
- Test Discovery: Configured to find tests matching
test_*.py,*_test.py, ortests.py - Coverage Settings:
- Tracks all project modules (models, metrics, utils, etc.)
- Generates HTML and XML coverage reports
- Currently set to 0% threshold (update as tests are added)
- Custom Markers:
@pytest.mark.unitfor unit tests@pytest.mark.integrationfor integration tests@pytest.mark.slowfor long-running tests
Shared Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory managementmock_config: Mock configuration objectsample_tensor&sample_numpy_array: Test datamock_generator&mock_discriminator: Mock modelsmock_data_loader: Mock data loadingclean_logs: Log directory managementsetup_random_seeds: Reproducible test runs- Device management fixtures for GPU/CPU testing
Development Commands
poetry run test: Run all testspoetry run tests: Alternative command (both work)- Standard pytest options are available (e.g.,
-v,-k,-m)
Instructions for Running Tests
-
Install dependencies:
poetry install -
Run all tests:
poetry run test -
Run specific test files:
poetry run test tests/test_setup_validation.py -
Run tests by marker:
poetry run test -m unit # Run only unit tests poetry run test -m integration # Run only integration tests poetry run test -m "not slow" # Skip slow tests -
View coverage report:
# After running tests, open the HTML report open htmlcov/index.html
Notes
- The testing infrastructure is ready for immediate use
- Coverage threshold is currently set to 0% to allow gradual test addition
- All validation tests pass, confirming the setup works correctly
- The
.gitignorehas been updated to exclude test artifacts and Claude-specific files - Poetry lock file is tracked in git for reproducible builds
Next Steps
Developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Gradually increase coverage threshold as tests are added