WeblogicScan
WeblogicScan 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 WebLogic scanner Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration as the project's package manager - Dependency Migration: Migrated existing
requestsdependency fromrequirements.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_*.pyand*_test.pyfiles - Coverage reporting with 80% threshold requirement
- HTML and XML coverage report generation
- Strict markers and configuration options
- Custom test markers:
unit,integration, andslow
- Test discovery patterns for
-
Coverage Configuration: Set up coverage.py with:
- Source directory targeting the
appmodule - Branch coverage enabled
- Exclusion patterns for test files and common Python patterns
- HTML reports in
htmlcov/and XML report ascoverage.xml
- Source directory targeting the
Project Structure
- Created proper testing directory structure:
tests/ ├── __init__.py ├── conftest.py ├── test_setup_validation.py ├── unit/ │ └── __init__.py └── integration/ └── __init__.py
Shared Fixtures
Created conftest.py with commonly needed pytest fixtures:
temp_dir: Temporary directory for file operationsmock_config: Mock configuration dictionarymock_response: Mock HTTP response objectmock_requests: Mock requests moduletest_data_dir: Path to test data directorysample_url: Sample WebLogic URLsample_payload: Sample test payloadreset_environment: Auto-reset environment variablescapture_logs: Log capturing fixturemock_file_system: Mock file system structure
Additional Setup
-
Updated .gitignore: Added comprehensive entries for:
- Python artifacts and caches
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/, etc.) - Virtual environments
- IDE files
- Claude Code settings (
.claude/*) - Note: Poetry lock file is NOT ignored (as per best practices)
-
Poetry Scripts: Configured both
poetry run testandpoetry run testscommands to run pytest -
Validation Tests: Created
test_setup_validation.pyto verify:- pytest installation and configuration
- Project structure integrity
- Module importability
- Fixture availability
- Marker functionality
- Coverage configuration
- Python path setup
How to Use
-
Install dependencies:
poetry install -
Run tests:
poetry run test # or poetry run tests -
Run specific test markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests -
View coverage report:
- Terminal: Coverage is shown after each test run
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The coverage threshold is set to 80% but can be adjusted in
pyproject.toml - Currently, the project's actual coverage is below the threshold (36.02%), which is expected since this PR only sets up the infrastructure
- Developers can now immediately start writing unit and integration tests using this infrastructure
- All test dependencies are isolated as development dependencies and won't affect production deployments