Skip to content

test: 100% line coverage + CI coverage gate#238

Open
AkashBrowserStack wants to merge 2 commits into
masterfrom
test/coverage-100-and-ci-gate
Open

test: 100% line coverage + CI coverage gate#238
AkashBrowserStack wants to merge 2 commits into
masterfrom
test/coverage-100-and-ci-gate

Conversation

@AkashBrowserStack

@AkashBrowserStack AkashBrowserStack commented Jun 12, 2026

Copy link
Copy Markdown

What & why

This SDK had no coverage enforcement in CI and sat at 86% locally. This PR raises it to 100% line coverage with meaningful tests and wires a hard CI gate so coverage can't silently regress.

Every line is executed by a real unit test — no # pragma skips, no coverage-gaming. Even the defensive optional-import fallbacks are exercised via reload-based tests rather than excluded.

Tests added

Area Coverage added
snapshot.py (new test_snapshot_units.py) log() CLI-ship failure; _wait_for_ready script-timeout adjust/restore failures; CORS-iframe origin-error skip; get_responsive_widths non-list + request failure; CDP resize → set_window_size fallback; _responsive_sleep invalid/unset; capture_responsive_dom invalid minHeight
percy/__init__.py (new test_init.py) percy_screenshot dispatch (unsupported driver, RemoteConnection → automate, AppiumConnection delegation when appium installed + helpful error when not, unknown → None); and reload-based tests that execute the robot-library and percy_snapshot optional-import fallbacks
robot_library.py parse-helper edge cases, full _parse_padding matrix, _get_driver missing-SeleniumLibrary error, Percy Screenshot keyword (+ region elements), reload-based test of the no-robotframework stub
driver_metadata.py newer-Selenium client_config.remote_server_addr fallback

Instrumentation / gate

  • .coveragercsource = percy, fail_under = 100, show_missing.
  • coverage + pytest-cov added to development.txt.
  • New make coverage runs every module (snapshot under percy exec --testing), combines parallel data, and enforces the threshold.
  • test.yml runs make coverage across the 3.8–3.10 matrix; new modules also added to make test.

Verification

make coverage -> TOTAL 514 stmts 0 miss 100%  (no pragma exclusions)  exit 0
pylint: 10.00/10

🤖 Generated with Claude Code

Raise unit coverage from 86% to 100% line coverage with meaningful tests
and wire a hard gate into CI so it cannot regress.

Tests added:
- test_snapshot_units.py (new): targeted unit tests for snapshot.py error
  and fallback paths the e2e suite doesn't reach — log() shipping failure,
  _wait_for_ready script-timeout adjust/restore failures, CORS-iframe
  origin error skip, get_responsive_widths non-list + request failure,
  CDP resize fallback to set_window_size, _responsive_sleep invalid/unset
  time, and capture_responsive_dom invalid minHeight handling.
- test_init.py (new): percy_screenshot dispatch — unsupported driver,
  RemoteConnection -> automate, AppiumConnection delegation when the
  appium package is present, helpful error when it is not, and unknown
  connection returning None.
- robot_library: parse-helper edge cases (_parse_widths/_parse_csv/
  _parse_json unsupported types, full _parse_padding matrix),
  _get_driver SeleniumLibrary-missing error, percy_screenshot keyword
  (basic + ignore/consider region elements), and a reload-based test of
  the no-robotframework stub (graceful ImportError).
- driver_metadata: command_executor._url -> client_config.remote_server_addr
  fallback for newer Selenium clients.

Instrumentation:
- Add .coveragerc (source=percy, fail_under=100, show_missing).
- Add coverage to development.txt; new Makefile `coverage` target runs
  every test module (snapshot under `percy exec --testing`), combines the
  parallel data, and enforces the threshold.
- test.yml runs `make coverage` across the Python matrix.
- Add the two new modules to `make test` as well.
- __init__: mark two genuinely-unreachable optional-import fallbacks with
  `# pragma: no cover` (robot_library never raises ImportError; percy.snapshot
  is the core module and always ships).
- gitignore coverage/npm artifacts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the two no-cover pragmas in percy/__init__ with reload-based
unit tests that actually execute the fallback lines:
- block percy.robot_library so the robot import fails and the
  except: pass branch runs (package still loads)
- inject a percy.snapshot stand-in lacking percy_snapshot so the
  import fails and the ModuleNotFoundError fallback is defined and
  raised.
Coverage stays at 100% line with no skipped lines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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