Skip to content

CHORE: refactor PR code coverage measurement - #542

Merged
Gaurav Sharma (bewithgaurav) merged 4 commits into
devfrom
bewithgaurav/pr-code-coverage-refactor
Aug 7, 2026
Merged

CHORE: refactor PR code coverage measurement#542
Gaurav Sharma (bewithgaurav) merged 4 commits into
devfrom
bewithgaurav/pr-code-coverage-refactor

Conversation

@bewithgaurav

Copy link
Copy Markdown
Collaborator

two changes to how PR code coverage gets measured. no product code touched.

pin the published report to one matrix leg

every Linux leg runs test.sh, writes django/coverage.xml, and publishes to the same artifact path. so the posted number is whichever leg wins the upload race. across the matrix that swings ~8.5 points (70.7% on django 3.2 up to 79.2% on django 6.0) for identical code, and the Windows job publishes nothing. pinned PublishCodeCoverageResults to the py314-django60 leg so the number is deterministic and reflects the newest supported stack (most backend paths exercised).

count the testapp suite, not just Django's

today only tests/runtests.py runs under coverage run. manage.py test (our own testapp suite) runs uninstrumented, so every regression test we add is invisible to the number. now:

  • tox wraps the testapp run in coverage run --parallel-mode
  • test.sh runs runtests in --parallel-mode too, then coverage combine merges both data sets before coverage xml
  • include narrowed from *mssql* to */mssql/* (segment-anchored, so a local checkout named mssql-django can't pull testapp files into the report)

net effect: coverage reflects the mssql backend exercised by both suites combined, and it's stable run to run.

verified locally against sql2022: combine unions hits across the two runs (1534 union 1540 = 1556 covered), report contains only mssql/*.py, testapp files excluded.

Pin the published coverage report to the py314-django60 Linux leg so the
posted number is deterministic instead of a nondeterministic upload race
across the matrix (which swings ~8.5 points on identical code).

Instrument the testapp suite so mssql-django's own tests count toward
coverage: wrap the testapp run in `coverage run --parallel-mode`, run the
Django suite in parallel mode too, then `coverage combine` both before
`coverage xml`. Narrow the include from `*mssql*` to `*/mssql/*` so it is
segment-anchored and never pulls testapp files into the report.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 24, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors CI code coverage measurement for pull requests to make the reported coverage value deterministic and to ensure coverage reflects both upstream Django tests and this repo’s testapp suite, without touching product code.

Changes:

  • Run the testapp suite under coverage run --parallel-mode so repo-owned regression tests contribute to coverage.
  • Run Django’s tests/runtests.py under coverage run --parallel-mode, then coverage combine the testapp + Django suite data before generating django/coverage.xml, narrowing include scope to */mssql/*.
  • Publish code coverage results only from the py314-django60 matrix leg to prevent nondeterministic “last upload wins” behavior across the Linux matrix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tox.ini Wraps the manage.py test run in coverage parallel mode so testapp contributes to coverage data.
test.sh Runs Django suite coverage in parallel mode, combines coverage data from repo root + django/, and tightens include filtering to the mssql/ package segment.
azure-pipelines.yml Pins PublishCodeCoverageResults to py314-django60 to avoid matrix upload races and stabilize the reported coverage number.

Resolve conflict from the Linux-steps refactor on dev: the coverage-publish
pin (PublishCodeCoverageResults@1 -> py314-django60 only) that #542 added
inline moved into the shared azure-pipelines-steps-linux.yml template, where
the task now lives. tox.ini + test.sh (coverage instrumentation of the testapp
suite via --parallel-mode + coverage combine) merged cleanly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bewithgaurav
Gaurav Sharma (bewithgaurav) merged commit 8398c6f into dev Aug 7, 2026
3 of 4 checks passed
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.

3 participants