test: measure coverage out-of-process for true 100%#125
Merged
Conversation
Collect coverage with 'coverage run -m pytest' instead of pytest-cov. pytest-cov starts measuring inside a pytest hook, after pytest has already imported the logprise package and its pytest plugin at startup, so their module-level definitions were never counted. Running coverage out-of-process starts measurement before those imports. - Switch build.yml and release.yml to 'coverage run -m pytest' + 'coverage xml'. - Drop the pytest-cov addopts from pyproject (a plain 'pytest' stays coverage-free; 'coverage run' reads [tool.coverage.run]). - Remove the conftest reload fixture: the out-of-process run measures the plugin's module-level code directly, so the reload hack is no longer needed. - Add tests for the two remaining uncovered branches (notify reporting failure, and an already-handled logger), reaching 100%.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #125 +/- ##
============================================
+ Coverage 72.50% 100.00% +27.50%
============================================
Files 2 2
Lines 240 240
Branches 38 38
============================================
+ Hits 174 240 +66
+ Misses 63 0 -63
+ Partials 3 0 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Coverage is now collected with 'coverage run -m pytest', so pytest-cov is unused. Depend on coverage[toml] directly (previously only pulled in transitively via pytest-cov); the [toml] extra is needed so coverage can read its [tool.coverage] config from pyproject.toml on Python 3.10. Also declare pytest directly, since the suite is run via 'coverage run -m pytest'.
Note that the extra is only needed for Python <= 3.10 and can be dropped once 3.10 support is removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Project coverage sat at ~76-79% even though the code is well tested. The cause is when coverage starts: pytest-cov begins measuring inside a pytest hook, after pytest has already imported the
logprisepackage and its pytest plugin at startup (via thepytest11entry point). Their module-level definitions (imports, class/function defs,appriser = Appriser()) therefore never registered as executed.PR #97 worked around this for
pytest_plugin.pywith a session-scoped fixture that reloaded the module under coverage. That only patched one file —__init__.pyhad the same gap — and left a reload hack in the test suite.Fix
Collect coverage out-of-process with
coverage run -m pytest, which starts measurement before pytest imports anything:build.yml/release.yml:coverage run -m pytest+coverage xmlinstead ofpytest --cov.pyproject.toml: drop the pytest-covaddopts(a plainpytestrun stays fast and coverage-free;coverage runreads[tool.coverage.run]). Note:--covandcoverage runtogether conflict, so it must go.conftest.py: remove the module-reload fixture — no longer needed.Result