Skip to content

test coverage - #43

Merged
dchou1618 merged 3 commits into
masterfrom
feature/test_coverage
Jul 6, 2026
Merged

dchou1618 merged 3 commits into
masterfrom
feature/test_coverage

Conversation

@dchou1618

Copy link
Copy Markdown
Owner

Description

Use pytest-cov to ensure test coverage of examples added.

Closes #42

@dchou1618 dchou1618 self-assigned this Jun 19, 2026
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Enforce 90% pytest coverage in CI using pytest-cov
🧪 Tests ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

Description

• Add pytest-cov to dev dependencies for local/CI coverage measurement.
• Run pytest with coverage reporting and fail CI below 90% threshold.
• Surface missing lines in CI output to guide test additions.
Diagram

graph TD
  CI[".github/workflows/cicd.yml"] --> DevDeps["requirements-dev.txt"] --> Pytest["pytest"] --> Cov["pytest-cov"] --> Gate{"Coverage >= 90%"}
  Cov --> Package["Algorithms package"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Move coverage args into pyproject.toml / pytest.ini
  • ➕ Single source of truth for local + CI runs
  • ➕ Shorter CI commands; easier to evolve options
  • ➖ Less obvious from the workflow alone what CI enforces
  • ➖ Requires adding/maintaining additional config file entries
2. Add a dedicated coverage job/artifact upload (e.g., Codecov)
  • ➕ Richer historical reporting and PR annotations
  • ➕ Can keep CI pass/fail separate from reporting concerns
  • ➖ Adds external dependency/service configuration
  • ➖ More moving parts than an inline fail-under gate

Recommendation: The current approach (inline pytest-cov invocation with --cov-fail-under) is the simplest way to enforce a hard coverage gate in CI. If the team expects to tune coverage settings frequently or wants parity with local runs, consider moving the coverage flags into project config (pyproject.toml/pytest.ini) while keeping CI as the enforcement point.

Files changed (2) +7 / -3

Other (2) +7 / -3
cicd.ymlRun pytest with coverage and enforce 90% minimum in CI +3/-2

Run pytest with coverage and enforce 90% minimum in CI

• Updates the CI workflow to run pytest with pytest-cov enabled. Adds terminal missing-line reporting and fails the job if coverage is below 90%.

.github/workflows/cicd.yml

requirements-dev.txtAdd pytest-cov to development requirements +4/-1

Add pytest-cov to development requirements

• Adds pytest-cov as a dev dependency for coverage measurement. Also fixes the missing trailing newline in the file.

requirements-dev.txt

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

@qodo-code-review

Copy link
Copy Markdown

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: Run Tests (CI)

Failed stage: Run tests with coverage [❌]

Failed test name: ""

Failure summary:

The action failed because the pytest coverage gate was not met:
- pytest -q --cov=Algorithms
--cov-report=term-missing --cov-fail-under=90 enforces a minimum total coverage of 90%.
- The run
completed with all tests passing (55 passed), but total coverage was only 80.24%, triggering: FAIL
Required test coverage of 90% not reached.
- Low-coverage modules include:
-
Algorithms/datastructs/hash_table/hash_table.py (49% coverage; many lines missing: 14, 20-23, 36-37,
40-46, 49-63, 66)
- Algorithms/datastructs/hash_table/cache.py (86% coverage; missing 22-24, 33,
39, 51, 61-66)
- Algorithms/datastructs/hash_table/bucket_hash_table.py (87% coverage; missing
14-18, 82-87)
Pytest exited with code 1 due to the coverage failure, causing the GitHub Action step
to fail.

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

315:  Successfully installed python-examples-0.1.0
316:  ##[group]Run pytest -q --cov=Algorithms --cov-report=term-missing --cov-fail-under=90
317:  �[36;1mpytest -q --cov=Algorithms --cov-report=term-missing --cov-fail-under=90�[0m
318:  shell: /usr/bin/bash -e {0}
319:  env:
320:  pythonLocation: /opt/hostedtoolcache/Python/3.12.13/x64
321:  PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.12.13/x64/lib/pkgconfig
322:  Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
323:  Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
324:  Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
325:  LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.13/x64/lib
326:  ##[endgroup]
327:  .......................................................                  [100%]
328:  =============================== warnings summary ===============================
329:  ../../../../../opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/torch/_subclasses/functional_tensor.py:362
330:  /opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/torch/_subclasses/functional_tensor.py:362: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
331:  cpu = _conversion_method_template(device=torch.device("cpu"))
332:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
333:  ---------- coverage: platform linux, python 3.12.13-final-0 ----------
334:  Name                                                     Stmts   Miss  Cover   Missing
335:  --------------------------------------------------------------------------------------
336:  Algorithms/datastructs/hash_table/bucket_hash_table.py      77     10    87%   14-18, 82-87
337:  Algorithms/datastructs/hash_table/cache.py                  87     12    86%   22-24, 33, 39, 51, 61-66
338:  Algorithms/datastructs/hash_table/hash_table.py             53     27    49%   14, 20-23, 36-37, 40-46, 49-63, 66
339:  Algorithms/slidingWindow/longestUnique.py                   31      0   100%
340:  --------------------------------------------------------------------------------------
341:  TOTAL                                                      248     49    80%
342:  FAIL Required test coverage of 90% not reached. Total coverage: 80.24%
343:  55 passed, 1 warning in 2.69s
344:  ##[error]Process completed with exit code 1.
345:  Node 20 is being deprecated. This workflow is running with Node 24 by default. If you need to temporarily use Node 20, you can set the ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION=true environment variable. For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

@qodo-code-review

qodo-code-review Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used

Grey Divider


Remediation recommended

1. Coverage gate is brittle 🐞 Bug ☼ Reliability
Description
CI now enforces --cov-fail-under=90 for Algorithms, but the current tests import modules that
contain significant method bodies that are never exercised (e.g., RandomizedCollection in
hash_table.py), which will reduce measured coverage and make the new gate prone to failing until
those lines are tested or excluded.
Code

.github/workflows/cicd.yml[R29-31]

+      - name: Run tests with coverage
+        run: |
+          pytest -q --cov=Algorithms --cov-report=term-missing --cov-fail-under=90
Evidence
The workflow change introduces a hard 90% coverage gate. The test suite imports
Algorithms.datastructs.hash_table.hash_table, but only tests RandomizedSet; the same imported
module also defines RandomizedCollection and there are no test references to it anywhere, so its
method bodies remain uncovered and reduce coverage once enforced. Similarly, the imported cache.py
and bucket_hash_table.py define __str__/__repr__ helpers that are not called anywhere in
tests/, leaving more uncovered lines under the same --cov=Algorithms measurement scope.

.github/workflows/cicd.yml[23-32]
tests/algorithms/test_hash_table.py[1-40]
Algorithms/datastructs/hash_table/hash_table.py[1-66]
tests/algorithms/test_cache.py[1-127]
Algorithms/datastructs/hash_table/cache.py[1-100]
tests/algorithms/test_bucket_hash_table.py[1-120]
Algorithms/datastructs/hash_table/bucket_hash_table.py[7-105]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow now runs pytest with coverage enforcement (`--cov-fail-under=90`). Several modules under `Algorithms/` that are imported by the existing tests contain code that is never executed by those tests (e.g., an entire extra class in `hash_table.py`, plus `__str__`/`__repr__` helpers), which reduces measured coverage and makes the 90% gate brittle.

## Issue Context
- `pytest-cov` measures executed vs. non-executed lines in imported source files under the specified `--cov` source.
- Current tests import these modules, but do not call the identified functions/methods, so their bodies remain uncovered.

## Fix Focus Areas
- .github/workflows/cicd.yml[29-31]
- Algorithms/datastructs/hash_table/hash_table.py[33-66]
- Algorithms/datastructs/hash_table/cache.py[60-66]
- Algorithms/datastructs/hash_table/bucket_hash_table.py[7-18]
- tests/algorithms/test_hash_table.py[1-40]
- tests/algorithms/test_cache.py[1-127]
- tests/algorithms/test_bucket_hash_table.py[1-120]

## What to change
Pick one (or combine):
1. **Add tests** that exercise `RandomizedCollection` and the `__str__`/`__repr__` helpers (simple smoke tests calling these methods is sufficient).
2. **Exclude intentionally-non-critical lines** from coverage (e.g., add `# pragma: no cover` to `__repr__`/`__str__`, or configure coverage omission via a config file).
3. **Adjust the gate scope/threshold** to match what is realistically covered today (e.g., lower `--cov-fail-under` or target a narrower `--cov` source until coverage is expanded).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@dchou1618
dchou1618 merged commit 6e51c5e into master Jul 6, 2026
4 of 5 checks passed
@dchou1618
dchou1618 deleted the feature/test_coverage branch July 6, 2026 02:37
This was referenced Jul 12, 2026
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.

Test coverage enforcement

1 participant