Skip to content

test: increasing unit test coverage to 95 percent#740

Open
mgama-deepgram wants to merge 7 commits into
mainfrom
increase_unit_test_coverage
Open

test: increasing unit test coverage to 95 percent#740
mgama-deepgram wants to merge 7 commits into
mainfrom
increase_unit_test_coverage

Conversation

@mgama-deepgram

@mgama-deepgram mgama-deepgram commented Jun 30, 2026

Copy link
Copy Markdown

Increase unit test coverage (~95%) + coverage in CI

  • Increases unit test coverage close to 90 percent (line rate increased from 54% to 96%, and branch rate from 32% to 95%)
  • Adding code coverage processes on the CI.yml workflow on the test job
  • The test job in the CI.yml workflow will now post the calculated code coverage as a PR comment
  • Replaces original PR that only included changes to ci.yml workflow docs: adding code coverage processes on ci.yml workflow #735

Adds a hand-written custom test suite that raises deepgram package coverage to the ~95% target (branch coverage enabled), wires coverage reporting into CI with an automatic PR comment, and configures coverage to focus on hand-maintainable logic rather than Fern-generated boilerplate. Also freezes the new tests and coverage config in .fernignore so they survive the next SDK regeneration.

What changed

  • CI (​.github/workflows/ci.yml)
    Runs on pull_request in addition to push.
    Test step now runs under coverage: pytest --cov=deepgram --cov-branch --cov-report=xml --cov-report=term-missing.
    Generates a coverage summary (CodeCoverageSummary) and posts/updates a sticky PR comment with the results (Python 3.13 matrix leg only); also writes it to the job summary.
    Grants the test job pull-requests: write so it can comment.

  • Coverage config (pyproject.toml)
    New [tool.coverage.run] / [tool.coverage.report]: branch coverage on, scoped to deepgram, with pure-generated code excluded (types/, requests/, init.py, version.py, unused core/http_sse/) so the metric reflects code that actually carries logic.

  • New tests (tests/custom/, ~170 test functions, many parametrized)
    test_http_endpoints_coverage.py — table-driven sweep of every REST endpoint (success + 400/403/non-JSON error branches, sync + async).
    test_http_retry_coverage.py — retry/backoff behavior.
    test_websocket_streaming_coverage.py — websocket streaming clients.
    test_speak_v2_coverage.py — Speak V2 (Flux TTS): the batch REST audio.generate streaming endpoint, connect header/handshake-failure branches, and the socket-client iteration/send/recv paths. Raises speak.v2 from 44% → 97%.
    test_core_utilities_coverage.py, test_branch_coverage_95.py, test_misc_coverage.py, test_more_branches_coverage.py — core utilities and remaining branch gaps.

  • Regen safety / housekeeping
    .fernignore — freezes all 8 new custom test files and pyproject.toml (Fern regenerates it, so the coverage config would otherwise be stripped). Documented in AGENTS.md.
    .gitignore — ignores the .coverage artifact and htmlcov/.
    Merged latest main (7.6.0 regen) to keep the branch current.

Testing
New tests use respx (HTTP) and in-process websocket fakes — no network / no WireMock dependency.
All Speak V2 coverage tests pass locally (50 across the v2 suite); CI runs the full suite under coverage on Python 3.10–3.13.

@mgama-deepgram mgama-deepgram changed the title Increase unit test coverage tests: Increase unit test coverage to 90 percent Jun 30, 2026
@mgama-deepgram
mgama-deepgram marked this pull request as ready for review June 30, 2026 17:00
@mgama-deepgram mgama-deepgram changed the title tests: Increase unit test coverage to 90 percent test: Increase unit test coverage to 90 percent Jun 30, 2026
@mgama-deepgram mgama-deepgram changed the title test: Increase unit test coverage to 90 percent test: increasing unit test coverage to 90 percent Jun 30, 2026
@mgama-deepgram mgama-deepgram changed the title test: increasing unit test coverage to 90 percent test: increasing unit test coverage to 95 percent Jul 2, 2026
@GregHolmes

Copy link
Copy Markdown
Contributor

Hi @mgama-deepgram this is great, however some of the files you've modified are generated files based on the API specs. I'd rather we didn't freeze files unless absolutely unavoidable.

@mgama-deepgram

Copy link
Copy Markdown
Author

@GregHolmes I removed all the changes that were done to files under src/deepgram/core and left only the new tests under tests/custom.
The code coverage is still really high, so that did not affect it that much.

@GregHolmes

Copy link
Copy Markdown
Contributor

@GregHolmes I removed all the changes that were done to files under src/deepgram/core and left only the new tests under tests/custom. The code coverage is still really high, so that did not affect it that much.

@mgama-deepgram would you not want your other test files in .fernignore? otherwise when regenerations done, it'll remove them.

@mgama-deepgram

Copy link
Copy Markdown
Author

@GregHolmes I removed all the changes that were done to files under src/deepgram/core and left only the new tests under tests/custom. The code coverage is still really high, so that did not affect it that much.

@mgama-deepgram would you not want your other test files in .fernignore? otherwise when regenerations done, it'll remove them.

Thanks for calling this out @GregHolmes I just added the tests files to the .fernignore file. I am new to use these type of files and regenerations, thanks for explaining.

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
src.deepgram 96% 92% 0
src.deepgram.agent 100% 100% 0
src.deepgram.agent.v1 98% 100% 0
src.deepgram.agent.v1.settings 100% 100% 0
src.deepgram.agent.v1.settings.think 100% 100% 0
src.deepgram.agent.v1.settings.think.models 97% 100% 0
src.deepgram.auth 100% 100% 0
src.deepgram.auth.v1 100% 100% 0
src.deepgram.auth.v1.tokens 97% 100% 0
src.deepgram.core 88% 82% 0
src.deepgram.errors 100% 100% 0
src.deepgram.helpers 100% 95% 0
src.deepgram.listen 100% 100% 0
src.deepgram.listen.v1 98% 93% 0
src.deepgram.listen.v1.media 97% 100% 0
src.deepgram.listen.v2 98% 93% 0
src.deepgram.manage 100% 100% 0
src.deepgram.manage.v1 100% 100% 0
src.deepgram.manage.v1.models 96% 100% 0
src.deepgram.manage.v1.projects 97% 100% 0
src.deepgram.manage.v1.projects.billing 100% 100% 0
src.deepgram.manage.v1.projects.billing.balances 96% 100% 0
src.deepgram.manage.v1.projects.billing.breakdown 97% 100% 0
src.deepgram.manage.v1.projects.billing.fields 97% 100% 0
src.deepgram.manage.v1.projects.billing.purchases 97% 100% 0
src.deepgram.manage.v1.projects.keys 96% 100% 0
src.deepgram.manage.v1.projects.members 97% 100% 0
src.deepgram.manage.v1.projects.members.invites 96% 100% 0
src.deepgram.manage.v1.projects.members.scopes 96% 100% 0
src.deepgram.manage.v1.projects.models 96% 100% 0
src.deepgram.manage.v1.projects.usage 98% 100% 0
src.deepgram.manage.v1.projects.usage.breakdown 97% 100% 0
src.deepgram.manage.v1.projects.usage.fields 97% 100% 0
src.deepgram.read 100% 100% 0
src.deepgram.read.v1 100% 100% 0
src.deepgram.read.v1.text 98% 100% 0
src.deepgram.self_hosted 100% 100% 0
src.deepgram.self_hosted.v1 100% 100% 0
src.deepgram.self_hosted.v1.distribution_credentials 96% 100% 0
src.deepgram.speak 100% 100% 0
src.deepgram.speak.v1 98% 97% 0
src.deepgram.speak.v1.audio 91% 80% 0
src.deepgram.speak.v2 98% 93% 0
src.deepgram.speak.v2.audio 98% 100% 0
src.deepgram.voice_agent 100% 100% 0
src.deepgram.voice_agent.configurations 95% 100% 0
src.deepgram.voice_agent.variables 95% 100% 0
Summary 95% (6426 / 6730) 92% (1405 / 1532) 0

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.

2 participants