← Back to Pull requests

[MRG] refactor(tests): remove test smells from the test suite #871

Open
unknown opened this pull request with 269 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 01, 2026 19:52 UTC
Author

Why

This PR refactors test smells in the test suite: patterns in test code that make tests harder to read, debug or trust, such as assertions that can never fail, loops and conditionals inside tests, and try/except blocks that hide failures. The smells were detected with TEMPY and refactored following the CATSPY test smell catalog, as part of a Software Quality course assignment at the Federal University of Ceará (UFC), Brazil.

Only files under tests/ are touched. No library code changes.

Commits

1. test: fix tests that could never fail
- test_pdfium_backend_import_error and test_import_error only asserted inside an except block that never ran, because pypdfium2 and matplotlib are already imported when camelot loads. They now simulate the failed import and assert on the result.
- test_cli_quiet passed --quiet without a value, so Click consumed --format as its value and the command exited with a usage error nobody checked. It now passes a value and asserts a clean exit with no warnings.
2. test: move test doubles to tests/doubles.py: the conversion backend stubs and the LTTextLine stub move out of the test modules.
3. test: replace try/except blocks with direct assertions: test_no_tables_found_* no longer catch the warning they are meant to forbid, and the SQLite export tests use contextlib.closing and check the exact table names.
4. test: replace loops and conditionals inside tests: loops over inputs become @pytest.mark.parametrize, an in-body skip becomes skipif, and a per-row assertion loop becomes one assertion that lists every bad row.
5. test: split the long CLI stream and output format tests: one test per behaviour, so the first failure no longer hides the rest.
6. test: tidy up two tests in test_errors.py: an empty pass stub gets a descriptive name and a docstring, and test_extraction_not_allowed also matches the error message.

How it was tested

  • Each commit passes ruff and the test files it touches on its own.

  • ruff check, ruff format --check and mypy camelot tests pass.
  • Diff: 269 lines (+201 / -68) across 3 files Reviewer: bosd Review duration: 22750m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 269 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.335
    Real PR Conversation Timeline
    1 comments
    "Review active on #871"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21% · Safe to merge
    21%