feat: Set up Python testing infrastructure with Poetry #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Python Testing Infrastructure Setup
Summary
This PR sets up a complete testing infrastructure for the Python scripts in this Ansible playbooks repository. The infrastructure uses Poetry as the package manager and pytest as the testing framework, providing a modern and efficient testing environment.
Changes Made
Package Management
pyproject.toml
pytest
(^8.0.0) - Core testing frameworkpytest-cov
(^5.0.0) - Coverage reportingpytest-mock
(^3.14.0) - Mocking utilitiesTesting Configuration
pytest Configuration: Comprehensive pytest settings in
pyproject.toml
including:unit
,integration
, andslow
Coverage Configuration:
scripts/python
Directory Structure
Testing Fixtures
Created comprehensive fixtures in
conftest.py
:temp_dir
: Temporary directory managementmock_config
: Mock configuration datasample_yaml_content
: Sample YAML for Ansible testingsample_json_data
: Sample JSON datamock_env_vars
: Environment variable mockingclean_environment
: Clean test environmentmock_file_system
: Mock file system structureDevelopment Commands
Poetry script commands configured:
poetry run test
- Run all testspoetry run tests
- Alternative command (both work)Git Configuration
Updated
.gitignore
with:__pycache__/
,*.pyc
, etc.).pytest_cache/
,.coverage
,htmlcov/
).claude/*
)poetry.lock
is NOT ignored (as per best practices)How to Use
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
Install Dependencies:
Run Tests:
Run Tests with Specific Markers:
View Coverage Report:
Notes
Future Recommendations
pytest-xdist
for parallel test execution