teemo
teemo copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with coverage reporting.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated all dependencies from
requirements.txtto Poetry - Development Dependencies: Added
pytest,pytest-cov, andpytest-mockas development dependencies
Testing Configuration
-
pytest Configuration: Configured pytest in
pyproject.tomlwith:- Test discovery patterns for
test_*.py,*_test.py, andtests.py - Coverage reporting with HTML and XML output formats
- Custom markers:
unit,integration, andslow - Strict mode options for better error detection
- Test discovery patterns for
-
Coverage Configuration: Set up coverage tracking for all main modules:
- Tracks:
brute,domainsites,lib,reverse, andsearchenginemodules - Excludes test files and
__init__.pyfiles from coverage - Generates reports in terminal, HTML, and XML formats
- Tracks:
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Infrastructure validation tests
├── unit/ # Unit tests directory
│ └── __init__.py
└── integration/ # Integration tests directory
└── __init__.py
Shared Fixtures (conftest.py)
Created comprehensive test fixtures including:
temp_dirandtemp_file: Temporary file system utilitiesmock_config: Mock configuration objectmock_requests: Mock HTTP requestsmock_dns_resolver: Mock DNS resolutionsample_domain_listandsample_ip_list: Test datamock_logger: Mock logging functionalitymock_file_system: Mock file operationsenvironment_vars: Environment variable managementmock_subprocess: Mock subprocess callscapture_output: Stdout/stderr capture utilitymock_time: Time-related mocking
Additional Updates
- Updated
.gitignore: Added entries for:- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/, etc.) - Python artifacts (
__pycache__/,*.pyc, etc.) - Virtual environments
- IDE files
- Claude settings (
.claude/*)
- Testing artifacts (
How to Use
Installing Dependencies
poetry install
Running Tests
Both of these commands work:
poetry run test
poetry run tests
Running Specific Test Categories
# Run only unit tests
poetry run pytest -m unit
# Run only integration tests
poetry run pytest -m integration
# Run non-slow tests
poetry run pytest -m "not slow"
Coverage Reports
After running tests, coverage reports are available:
- Terminal: Displayed automatically with missing lines
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The coverage threshold is currently set to 0% due to Python 2 syntax in existing code preventing proper parsing
- The
argparsedependency was removed as it's built into Python 3 - All Poetry commands should be run with
poetry runprefix to use the virtual environment - The infrastructure is ready for developers to start writing actual unit and integration tests
Next Steps
- Start writing unit tests for individual modules
- Add integration tests for end-to-end functionality
- Gradually increase coverage threshold as more tests are added
- Consider updating existing code to Python 3 syntax for better coverage tracking