Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Add Comprehensive Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the aws-sso-util project using pytest and Poetry. The setup provides a foundation for writing unit tests, integration tests, and maintaining code coverage standards.

Changes Made

Testing Dependencies

  • Added pytest (^7.4.0) - Core testing framework
  • Added pytest-cov (^4.1.0) - Coverage reporting plugin
  • Added pytest-mock (^3.11.1) - Mocking utilities

Configuration

  • pytest configuration in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, and slow
    • Coverage reporting with HTML and XML output
    • Verbose output with strict marker enforcement
  • Coverage configuration:

    • Source coverage for aws_sso_util and aws_sso_lib
    • 80% coverage threshold (configurable)
    • Exclusions for test files, __init__.py, and vendored code
    • HTML reports in htmlcov/ directory

Directory Structure

cli/
├── tests/
│   ├── __init__.py
│   ├── conftest.py          # Shared fixtures for CLI tests
│   ├── test_setup_validation.py  # Validation tests
│   ├── unit/
│   │   └── __init__.py
│   └── integration/
│       └── __init__.py

lib/
├── tests/
│   ├── __init__.py
│   ├── conftest.py          # Shared fixtures for lib tests
│   ├── unit/
│   │   └── __init__.py
│   └── integration/
│       └── __init__.py

Shared Fixtures

Both conftest.py files provide common fixtures including:

  • temp_dir - Temporary directory management
  • mock_aws_config_dir / mock_aws_config - AWS configuration mocking
  • mock_sso_cache_dir / mock_sso_cache - SSO cache mocking
  • mock_boto3_client / mock_boto3_session - AWS API mocking
  • mock_environment - Environment variable mocking
  • sample_yaml_config / sample_sso_token - Test data fixtures
  • mock_click_context - CLI testing utilities
  • capture_logs / capture_stdout - Output capture fixtures

Poetry Commands

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work)

Updated Files

  • .gitignore - Added testing artifacts and Claude directories
  • Migrated from deprecated [tool.poetry.dev-dependencies] to [tool.poetry.group.dev.dependencies]

How to Use

  1. Install dependencies:

    cd cli && poetry install --with dev
    cd ../lib && poetry install --with dev
  2. Run tests:

    # From cli directory
    poetry run test
    
    # Or with specific markers
    poetry run pytest -m unit
    poetry run pytest -m integration
  3. View coverage report:

    # HTML report will be in htmlcov/index.html
    open htmlcov/index.html

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests for individual functions and classes
  2. Create integration tests for end-to-end workflows
  3. Mock AWS services effectively using provided fixtures
  4. Maintain code coverage standards
  5. Run tests in CI/CD pipelines using the XML coverage output

Notes

  • The validation tests (test_setup_validation.py) verify the infrastructure is working correctly
  • Coverage warnings for "no data collected" are expected until actual tests are written
  • The 80% coverage threshold is configured but can be adjusted in pyproject.toml
  • All pytest CLI options remain available when using the Poetry command

- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with HTML and XML output
- Create test directory structure for both cli and lib packages
- Add shared fixtures in conftest.py for common test scenarios
- Update .gitignore with testing and Claude-related entries
- Add Poetry script commands for running tests
- Include validation tests to verify infrastructure setup
@iainelder
Copy link
Collaborator

@Libbl, thank you for the submission! I'm on vacation now, and I'll review this in July.

A better test infrastructure will help us to maintain the project and have confidence that everything still works as it should.

@llbbl
Copy link
Author

llbbl commented Jun 16, 2025

Hey, you’re welcome. Let me know if you want a more unified testing approach and see if I can get it set up at the project root instead.

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.

2 participants