Skip to content

refactor: Clean up flake8 warnings in test suite (151 warnings) #402

@blalterman

Description

@blalterman

Background

Test suite has 151 flake8 warnings (all in tests/ directory, production code is clean).

These are pre-existing technical debt, not introduced by v0.2.0 changes. The warnings don't affect functionality but reduce code cleanliness and maintainability.

Warnings Breakdown

Category Count Severity Description
F401 77 Medium Unused imports
F841 17 Medium Unused variables
E402 32 Low Module imports not at top of file
D205 16 Low Docstring formatting (missing blank line)
E226 5 Low Missing whitespace around operators
Others 4 Low Misc style issues (E203, F811, F541, W291)

Total: 151 warnings across test files

Scope

Tier 2: Important (Recommended)

  • Remove unused imports (F401 - 77 instances)
    • Use autoflake --remove-all-unused-imports
    • Review for false positives (e.g., fixtures, type hints)
  • Remove unused variables (F841 - 17 instances)
    • Use autoflake --remove-unused-variables
    • Verify tests still validate expected behavior
  • Fix redefinition (F811 - 1 instance)
    • Manual fix in test_sidc.py
  • Fix f-string placeholders (F541 - 1 instance)
    • Manual fix in test_base.py

Estimated Time: 2-3 hours (mostly automated)

Tier 3: Nice-to-Have (Optional)

  • Fix import ordering (E402 - 32 instances)
    • Use isort tests/
    • May require test file restructuring
  • Fix docstring formatting (D205 - 16 instances)
    • Use docformatter --in-place
    • Add blank lines between summary and description
  • Fix whitespace issues (E226, E203, W291 - 6 instances)
    • Manual fixes or black re-run

Estimated Time: 1-2 hours

Value Propositions

Metric Tier 2 (Unused Code) Tier 3 (Style)
Time 2-3 hours 1-2 hours
Code Quality +10% (removes clutter) +5% (consistency)
Maintainability High (easier to read) Medium (marginal)
Risk Low (tests validate) Very Low (cosmetic)
LOC Reduction ~94 lines (imports+vars) Minimal

Implementation Plan

Step 1: Install Tools

pip install autoflake isort docformatter

Step 2: Tier 2 Cleanup (Recommended)

# Preview changes
autoflake --remove-all-unused-imports --remove-unused-variables \
  --in-place --recursive tests/ --check

# Apply automated fixes
autoflake --remove-all-unused-imports --remove-unused-variables \
  --in-place --recursive tests/

# Manual review for false positives
git diff tests/

# Run tests to verify
pytest -q

# Commit
git add tests/
git commit -m "refactor(tests): remove unused imports and variables

Remove 94 unused imports (F401) and variables (F841) from test suite.

- Reduces test file size by ~94 lines
- Improves code clarity and maintainability
- Automated via autoflake with manual review

Resolves #402 (Tier 2 scope)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>"

Step 3: Tier 3 Cleanup (Optional)

# Fix import ordering
isort tests/

# Fix docstring formatting
docformatter --in-place --recursive tests/

# Run tests again
pytest -q

# Commit
git add tests/
git commit -m "style(tests): fix import ordering and docstring formatting

- Reorder imports to PEP8 standard (E402)
- Add blank lines in docstrings (D205)
- Fix whitespace issues (E226, E203, W291)

Resolves #402 (Tier 3 scope)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>"

Dependencies

None - independent cleanup task. Can be done anytime post-v0.2.0 release.

Timeline

Target: v0.2.1 or v0.3.0 timeframe (within 1-2 weeks of v0.2.0 release)

Priority: Medium - improves code quality but doesn't affect functionality

Success Criteria

  • Flake8 check on tests/ passes with <10 warnings (allow for unavoidable style preferences)
  • All pytest tests still pass (1,557 test cases)
  • Code review confirms no false positive removals
  • Test coverage maintained at ≥95%

Notes

  • Production code (solarwindpy/) already has zero flake8 warnings
  • These warnings are pre-existing technical debt, not introduced by recent changes
  • The publish workflow only checks flake8 solarwindpy/, so these don't block releases
  • v0.1.5 released successfully with these same warnings

This issue tracks test code quality improvement, not a critical bug fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:mediumMedium priority - normal timelinepythonPull requests that update python code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions