Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Add Comprehensive Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the objkt-swap project, providing developers with a ready-to-use testing environment for writing unit and integration tests.

Changes Made

  • Package Management: Set up Poetry as the package manager with pyproject.toml configuration
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Testing Configuration: Configured comprehensive pytest settings with:
    • Test discovery patterns for multiple naming conventions
    • Coverage reporting (HTML, XML, terminal)
    • Custom test markers (unit, integration, slow)
    • Strict configuration options
  • Directory Structure: Created proper testing hierarchy:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures and test configuration
    ├── unit/                # Unit tests directory
    └── integration/         # Integration tests directory
    
  • Shared Fixtures: Comprehensive fixture library in conftest.py including:
    • Temporary directory and file fixtures
    • Mock SmartPy context and configuration objects
    • Sample token data and addresses for testing
    • Blockchain context mocks
  • Validation Tests: Infrastructure validation test suite to ensure setup works correctly
  • Git Configuration: Updated .gitignore with testing-related entries and development files

Testing Instructions

Running Tests

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run tests with coverage report
poetry run pytest --cov

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m slow          # Slow tests only

# Run validation tests
poetry run pytest tests/test_infrastructure_validation.py -v

Coverage Reports

  • HTML coverage report: htmlcov/index.html
  • XML coverage report: coverage.xml
  • Terminal coverage summary included with test output

Dependencies & Configuration

Key Dependencies

  • pytest: Main testing framework
  • pytest-cov: Coverage reporting and analysis
  • pytest-mock: Enhanced mocking capabilities
  • smartpy: Smart contract development framework

Configuration Notes

  • Coverage threshold set to 0% initially due to SmartPy syntax compatibility
  • All SmartPy files (.py files with SmartPy syntax) will show coverage warnings - this is expected
  • Poetry lock file is tracked in version control for reproducible builds
  • Testing configuration is centralized in pyproject.toml

Development Workflow

With this infrastructure, developers can now:

  1. Write comprehensive unit and integration tests
  2. Use shared fixtures for common testing scenarios
  3. Generate coverage reports to track test completeness
  4. Run tests with consistent configuration across environments
  5. Leverage mocking capabilities for testing smart contract interactions

The testing environment is immediately ready for development - no additional setup required.

Add complete testing setup with Poetry package manager, pytest configuration,
and testing directory structure including fixtures and validation tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant