Skip to content

feat: Add comprehensive Python testing infrastructure#24

Open
llbbl wants to merge 1 commit into
MythicAgents:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Add comprehensive Python testing infrastructure#24
llbbl wants to merge 1 commit into
MythicAgents:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 3, 2025

Copy link
Copy Markdown

Add Complete Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Apfell project, providing developers with all the necessary tools and configurations to write and run tests effectively.

Changes Made

  • Package Management: Set up Poetry as the package manager with pyproject.toml configuration
  • Testing Dependencies: Added pytest ecosystem packages:
    • pytest (main testing framework)
    • pytest-cov (coverage reporting)
    • pytest-mock (mocking utilities)
  • Project Structure: Created organized test directory structure:
    • tests/ (main test directory)
    • tests/unit/ (unit tests)
    • tests/integration/ (integration tests)
    • Each directory includes proper __init__.py files
  • Configuration: Comprehensive pytest and coverage configuration in pyproject.toml:
    • Test discovery patterns
    • Coverage reporting (HTML, XML formats)
    • 80% coverage threshold
    • Custom markers (unit, integration, slow)
    • Strict configuration for reliability
  • Shared Fixtures: Created tests/conftest.py with reusable fixtures:
    • Temporary directory management
    • Mock objects for agents, tasks, callbacks
    • Sample configuration data
    • File system mocking
    • Environment variable setup
  • Validation: Added infrastructure validation tests to verify setup
  • Dependencies: Migrated existing dependencies from chainbreaker's requirements.txt
  • Git Configuration: Updated .gitignore with testing-related exclusions

Testing Infrastructure Features

Running Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=Payload_Type

# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run with verbose output
poetry run pytest -v

Coverage Reporting

  • HTML Report: Generated in htmlcov/ directory
  • XML Report: Generated as coverage.xml
  • Terminal Report: Shows missing lines during test runs
  • Threshold: 80% coverage requirement (configurable)

Available Fixtures

The conftest.py provides comprehensive fixtures for testing:

  • temp_dir: Temporary directory management
  • sample_config: Standard configuration dictionary
  • mock_agent, mock_task, mock_callback: Mock Mythic objects
  • mock_file_system: File system testing utilities
  • mock_environment_vars: Environment variable setup

Custom Markers

  • @pytest.mark.unit: Mark unit tests
  • @pytest.mark.integration: Mark integration tests
  • @pytest.mark.slow: Mark slow-running tests

Validation

The infrastructure has been validated with comprehensive tests in test_infrastructure_validation.py that verify:

  • ✅ Pytest functionality and configuration
  • ✅ All fixtures are working properly
  • ✅ Coverage reporting is configured correctly
  • ✅ Project structure is in place
  • ✅ Package management is functional

Next Steps

Developers can now:

  1. Install dependencies: poetry install
  2. Start writing tests: Add test files to tests/unit/ or tests/integration/
  3. Run tests: poetry run pytest
  4. Check coverage: View reports in htmlcov/index.html
  5. Use fixtures: Import and use shared fixtures from conftest.py

Configuration Notes

  • Poetry lock files are tracked in git (as recommended)
  • Coverage excludes common directories (venv, node_modules, etc.)
  • Pytest is configured with strict settings for reliability
  • All testing artifacts are properly gitignored

This infrastructure provides a solid foundation for comprehensive testing of the Apfell payload system.

- Set up Poetry package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as test dependencies
- Configure pytest with coverage reporting (80% threshold, HTML/XML output)
- Create structured test directories (tests/, unit/, integration/)
- Add comprehensive conftest.py with shared fixtures for mocking
- Update .gitignore with testing and coverage exclusions
- Add validation tests to verify infrastructure setup
- Configure custom pytest markers (unit, integration, slow)
- Migrate existing dependencies from chainbreaker requirements.txt
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