Fix pytest coverage without pytest-cov - #26151
Shayaan Tanveer (babaJaan01) wants to merge 2 commits into
Conversation
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
|
@microsoft-github-policy-service agree |
| if importlib.util.find_spec("pytest_cov") is not None: | ||
| return [*args, "--cov=.", "--cov-branch"], None | ||
|
|
||
| import coverage |
There was a problem hiding this comment.
Issue · Please address or respond
coverage.Coverage() defaults to branch=False, so this fallback never records arcs. As a result, has_branch_coverage() will always disable branch coverage when pytest-cov is absent, unlike the existing --cov-branch path. Initialize the fallback with branch=True (and equivalent source configuration if needed) and assert the collected fallback data contains branch arcs.
There was a problem hiding this comment.
Okay so updated the fallback to use coverage.Coverage(branch=True) and also added a test to confirm the no-pytest-cov fallback saves branch arcs
|
Result: Verification detailsVerification: Isolated verification observed failures that were not classified as caused by this PR: Dependency and test discovery preflight, Offline Python dependency bootstrap. The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Summary: The fallback coverage lifecycle was exercised with a fake coverage module and passed, and all changed Python files compiled successfully. The PR's targeted pytest suite could not run because the offline wheelhouse lacked `coverage`, causing dependency bootstrap to fail and leaving the virtual environment without pytest. Consequently, actual coverage collection, reporting, and branch detection remain unverified. Confidence is limited to the fallback plugin lifecycle and syntax. Test runs: 2 passed, 2 failed, 1 not run
|
|
Result: Verification detailsVerification: Isolated verification observed failures that were not classified as caused by this PR: pytest adapter coverage tests, Offline Python dependency bootstrap, Fallback smoke check from package directory, Fallback smoke check using created virtual environment. Summary: The targeted coverage test module could not collect because `coverage` was unavailable, and the offline wheelhouse could not install it. A dependency-free ad-hoc check passed for fallback lifecycle, pytest-cov selection, user arguments, plugin registration, and branch-arc detection. No PR-caused failure was observed, but real coverage collection/reporting remains unverified in this environment. Test runs: 2 passed, 4 failed
❌
|
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Fixes #25724
Fall back to coverage.py when coverage is requested without pytest-cov installed. Branch coverage is now derived from the collected coverage data.
Testing:
.venv/bin/python -m pytest python_files/tests/pytestadapter/test_coverage.py -q.venv/bin/python python_files/tests/run_all.py— 224 passed, 2 skipped