Phase 2: Test Coverage - Fix All Failing Tests #54
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.
Phase 2: Test Coverage Enhancement
This PR implements comprehensive improvements to test quality and coverage as part of the DevOps foundation initiative.
Overview
3 commits addressing test reliability, code quality warnings, and coverage gaps:
Phase 2a: Test Fixes
Fixed 12 failing tests broken by Phase 3 security API changes:
Changes
profile="default"patternConfigLoader.load()andget_profile_info()stdoutvsoutput)getpass.getpassmocking for interactive testsFiles Modified
tests/test_cli/test_setup.py: 4 tests fixedtests/test_domains/test_configuration.py: 6 tests fixedtests/test_integration.py: 1 test fixedtests/test_integration/test_secure_config.py: 1 test fixedResult: 355 tests passing (was 343 passing, 12 failing)
Phase 2b: Warning Reduction
Reduced pytest warnings from 56 to 5 by addressing deprecations and incorrect markers:
Fixes Applied
Pydantic V2 Migration (
src/opnsense_mcp/core/models.py)Configtomodel_config = ConfigDictOPNsenseConfigPytest Asyncio Markers (6 test files)
@pytest.mark.asynciofrom classes with synchronous methodsFiles Modified
src/opnsense_mcp/core/models.pytests/test_core/test_client_basic.pytests/test_core/test_config_loader.pytests/test_core/test_exceptions.pytests/test_core/test_models.pytests/test_core/test_connection.pytests/test_core/test_state.pyResult: 56 → 5 warnings (remaining are RuntimeWarnings in network_services tests)
Phase 2c: Coverage Enhancement
Improved overall coverage by 2.62 percentage points with 43 new comprehensive tests:
Coverage Improvements
shared/error_sanitizer.pyshared/error_handlers.pycli/delete.pyNew Test Files
tests/test_shared/test_error_sanitizer.py(30 tests)Comprehensive testing of error message sanitization:
log_error_safely()function behaviortests/test_cli/test_delete.py(13 tests)Complete coverage of profile deletion workflow:
--force,-f) behaviorBug Fix
src/opnsense_mcp/cli/delete.py: Fixed typer.Exit() handlingexcept typer.Exitblock before genericExceptionhandlerExit(0)from being caught and converted toExit(1)Test Results
Impact
Quality Improvements
Coverage Gains
Future Work
To reach 80%+ overall coverage would require testing large domain modules:
domains/certificates.py(425 lines, 21% coverage)domains/users.py(508 lines, 12% coverage)domains/dns_dhcp.py(430 lines, 14% coverage)domains/traffic_shaping.py(461 lines, 14% coverage)These could be addressed in a follow-up phase with focused domain testing.
Checklist
🤖 Generated with Claude Code