Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Glass security reconnaissance tool. The setup uses Poetry as the package manager and pytest as the testing framework, providing a modern and maintainable testing environment.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Version Constraints: Maintained compatibility with Python 3.7.3+ and urllib3 1.25.8

Testing Framework

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with 80% threshold
    • Added HTML and XML coverage report generation
    • Configured strict markers and verbose output
  • Testing Dependencies (dev group):

    • pytest ^7.2.0 - Core testing framework
    • pytest-cov ^4.0.0 - Coverage reporting
    • pytest-mock ^3.10.0 - Mocking utilities

Project Structure

tests/
├── __init__.py
├── conftest.py           # Common fixtures and test configuration
├── test_setup_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Test Fixtures (in conftest.py)

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration objects
  • mock_response - Mock HTTP responses
  • sample_data - Sample test data
  • mock_file_system - Mock file system structure
  • mock_api_client - Mock API client
  • capture_logs - Log capture utility
  • mock_color_output - Colorama mocking
  • mock_proxy_settings - Proxy configuration mocking

Test Markers

  • @pytest.mark.unit - Fast, isolated unit tests
  • @pytest.mark.integration - Integration tests (may require external resources)
  • @pytest.mark.slow - Slow-running tests

Additional Configuration

  • Updated .gitignore with testing and Poetry entries
  • Created validation tests to verify the setup

How to Use

Installation

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

Running Tests

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration

# Run specific test file
poetry run pytest tests/test_setup_validation.py

# Run with coverage report
poetry run pytest --cov

# Generate HTML coverage report
poetry run pytest --cov --cov-report=html

Writing Tests

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use the provided fixtures from conftest.py
  4. Mark tests appropriately with @pytest.mark.unit, etc.

Notes

  • The coverage threshold is set to 80% - tests will fail if coverage drops below this
  • Coverage reports exclude test files, cache directories, and virtual environments
  • The setup is compatible with the existing project structure and dependencies
  • Poetry lock file should be committed to ensure reproducible builds

Validation

All validation tests pass, confirming:

  • Python version compatibility
  • Project imports work correctly
  • Fixtures are properly configured
  • Test markers are registered
  • Directory structure is correct
  • Coverage reporting is functional

- Add Poetry package manager configuration with pyproject.toml
- Configure pytest with coverage reporting (80% threshold)
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create tests directory structure with unit/integration subdirectories
- Configure common fixtures in conftest.py for testing utilities
- Set up test markers for unit, integration, and slow tests
- Add Poetry scripts for running tests (poetry run test/tests)
- Update .gitignore with testing and Poetry-related entries
- Create validation tests to verify testing setup works correctly
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