Skip to content

test(dataviewer): improve backend Python test coverage toward OpenSSF Silver threshold #441

@WilliamBerryiii

Description

@WilliamBerryiii

Issue Description

Background

The dataviewer backend has 46 source files in data-management/viewer/backend/src/ and 29 test files in data-management/viewer/backend/tests/. While this is the most mature test suite outside of training/, coverage gaps remain. The existing CI workflow (dataviewer-backend-pytests.yml) already uploads coverage to Codecov with the pytest-dataviewer flag.

This issue focuses on improving coverage of untested or under-tested source files to contribute toward the OpenSSF Silver ≥50% overall coverage threshold.

Current Infrastructure

  • CI workflow: .github/workflows/dataviewer-backend-pytests.yml — runs uv run pytest -v --cov=src --cov-report=xml
  • Codecov flag: pytest-dataviewer with paths: ["data-management/viewer/backend/src/"]
  • Test dependencies: pytest, pytest-asyncio, pytest-cov, httpx, hypothesis, schemathesis (in pyproject.toml)
  • Pytest config: asyncio_mode = "auto", testpaths = ["tests"]
  • No [tool.coverage.run] in backend pyproject.toml — coverage measured via CLI flags only

Coverage Gap Analysis Needed

Identify which of the 46 source files have no corresponding test files or low coverage:

  • Compare src/ file list against tests/ file list
  • Run local coverage report to identify files below threshold
  • Prioritize by: (1) business logic complexity, (2) API surface area, (3) error handling paths

Suggested Fix

1. Generate Coverage Gap Report

cd data-management/viewer/backend
uv run pytest -v --cov=src --cov-report=term-missing --cov-report=html

Review htmlcov/index.html to identify uncovered modules.

2. Add Missing Test Files

For each untested source module, create a corresponding test file following existing patterns:

  • Test file: tests/test_{module_name}.py
  • Class-based grouping: class TestModuleName:
  • Mock external deps: Azure SDK, filesystem, auth providers
  • Test public API surfaces only

3. Add Coverage Configuration

Add a [tool.coverage.run] section to data-management/viewer/backend/pyproject.toml:

[tool.coverage.run]
source = ["src"]
branch = true
omit = ["src/**/conftest.py", "src/**/__init__.py"]

[tool.coverage.report]
show_missing = true
precision = 2

4. Validate

  • All new tests pass without live Azure services
  • Coverage report shows improvement over baseline
  • CI workflow continues to upload accurate coverage data

Acceptance Criteria

  • Coverage gap analysis completed — uncovered source files identified and documented
  • Test files added for highest-impact uncovered modules
  • [tool.coverage.run] section added to backend pyproject.toml
  • All tests pass in CI without external service dependencies
  • pytest-dataviewer Codecov flag shows measurable coverage improvement
  • Coverage increase contributes to overall project coverage toward ≥50%

Implementation Notes

Related Issues

OpenSSF IDs: regression_tests_added50

Metadata

Metadata

Labels

ci/cdCI/CD pipeline and automationenhancementNew feature or improvement requesttestingTesting-related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions