Skip to content

Add CLI Retry Parameters and Improve Test Script Structure - #539

Merged
martin-majlis merged 1 commit into
masterfrom
remove-incorrect-cli-integration-test
Apr 3, 2026
Merged

martin-majlis merged 1 commit into
masterfrom
remove-incorrect-cli-integration-test

Conversation

@martin-majlis

Copy link
Copy Markdown
Owner

Summary

This PR adds global --max-retries and --retry-wait options to the CLI and refactors the test script to use variables for better maintainability.

Features Added

CLI Retry Parameters

  • --max-retries: Maximum number of retry attempts for transient errors (HTTP 429, 5xx, timeouts, connection errors). Default: 3
  • --retry-wait: Base wait time in seconds between retries using exponential backoff. Default: 1.0
  • Global Options: These parameters apply to all CLI commands that make API requests
  • Help Documentation: Updated CLI.rst with comprehensive usage examples

Test Script Improvements

  • Variable System: Introduced RETRY_PARAMS and UV_CMD variables in test_cli.sh
  • Maintainability: All 67 functional test commands now use centralized parameters
  • Easy Configuration: Change retry settings for all tests by modifying one line
  • DRY Principle: Eliminated code duplication across test commands

Changes Made

Core CLI Implementation

  • Added retry options to _common_options in wikipediaapi/commands/base.py
  • Updated create_wikipedia_instance() to accept retry parameters
  • Modified all command functions across all CLI modules to pass retry parameters
  • Updated unit tests to verify retry parameter handling

Documentation

  • Enhanced CLI.rst with retry configuration section and examples
  • Added comprehensive usage examples showing different retry strategies

Test Infrastructure

  • Refactored tests/cli/test_cli.sh to use variables for common parameters
  • Updated all test commands to use --max-retries 10 --retry-wait 5
  • Removed problematic images_nonexistent test
  • Recorded new expected outputs for all commands

Usage Examples

# Use custom retry settings
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0

# Disable retries entirely
wikipedia-api search "Python" --max-retries 0

# Aggressive retrying for unreliable connections
wikipedia-api geosearch --coord "51.5074|-0.1278" --max-retries 10 --retry-wait 3.0

Benefits

  1. Robust Error Handling: CLI now gracefully handles network issues and rate limiting
  2. User Control: Users can customize retry behavior based on their needs
  3. Better Testing: Test script is now much easier to maintain and modify
  4. Consistent Behavior: All commands use the same retry configuration
  5. Backward Compatibility: All existing functionality remains unchanged

Testing

  • All 67 CLI tests now use retry parameters
  • Unit tests verify retry parameter passing
  • Help commands correctly exclude retry parameters
  • Code formatting and type checking pass

Files Changed

  • wikipediaapi/commands/base.py - Added retry options and factory function
  • wikipediaapi/commands/*.py - Updated all command functions
  • tests/cli/test_cli.sh - Refactored to use variables
  • tests/cli_test.py - Added retry parameter tests
  • CLI.rst - Updated documentation
  • Makefile - Fixed ruff check ordering

This improvement makes the CLI more robust for production use while significantly improving the maintainability of the test infrastructure.

@codecov

codecov Bot commented Apr 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.36%. Comparing base (2d4cbb8) to head (a241cf5).
⚠️ Report is 86 commits behind head on master.

Files with missing lines Patch % Lines
wikipediaapi/commands/geo_commands.py 0.00% 2 Missing ⚠️
wikipediaapi/commands/search_commands.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #539   +/-   ##
=======================================
  Coverage   94.36%   94.36%           
=======================================
  Files          72       72           
  Lines        3339     3339           
=======================================
  Hits         3151     3151           
  Misses        188      188           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martin-majlis
martin-majlis merged commit 2a3fc1f into master Apr 3, 2026
41 of 42 checks passed
@martin-majlis
martin-majlis deleted the remove-incorrect-cli-integration-test branch April 3, 2026 19:01
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.

1 participant