canonical / craft-cli

https://canonical-craft-cli.readthedocs-hosted.com/en/latest/
GNU Lesser General Public License v3.0
9 stars 15 forks source link

tools: call 'coverage' directly #155

Closed tigarmo closed 1 year ago

tigarmo commented 1 year ago

The problem: when using pytest-cov to integrate coverage with the test run, there is a 'race' between pytest-cov and the pytest plugin provided by craft-cli (the emitter). When craft-cli's plugin is loaded first, it necessitates importing the main 'craft_cli' package, which in turn imports dispatcher.py, messages.py, etc.

As a result, all the top-level lines (class and function definitions, global-variables, etc) are loaded before coverage starts running, meaning that they are marked as 'hits' because they are never "loaded again" during the tests. Instead, use coverage specifically so that it's always set-up before the whole importing starts.

codecov[bot] commented 1 year ago

Codecov Report

Merging #155 (0a3da0f) into main (710760e) will increase coverage by 25.38%. The diff coverage is 100.00%.

:exclamation: Current head 0a3da0f differs from pull request most recent head 69ffe16. Consider uploading reports for the commit 69ffe16 to get more accurate results

@@             Coverage Diff             @@
##             main     #155       +/-   ##
===========================================
+ Coverage   68.87%   94.25%   +25.38%     
===========================================
  Files           6        7        +1     
  Lines         983      992        +9     
  Branches      187      187               
===========================================
+ Hits          677      935      +258     
+ Misses        299       53      -246     
+ Partials        7        4        -3     
Impacted Files Coverage Δ
craft_cli/dispatcher.py 99.09% <100.00%> (+18.26%) :arrow_up:
craft_cli/messages.py 100.00% <100.00%> (+32.06%) :arrow_up:

... and 5 files with indirect coverage changes

tigarmo commented 1 year ago

Merging #155 (https://github.com/canonical/craft-cli/commit/0a3da0f8fac931e36561fc4d972bf385671f8d10) into main (https://github.com/canonical/craft-cli/commit/710760ec9ea1634f8e4361d468ec4b2e0dfc20ec) will increase coverage by 25.38%.

If only it were always this easy huh