简体   繁体   English

Python 单元测试的增量代码覆盖率?

[英]Incremental code coverage for Python unit tests?

How can I get an incremental report on code coverage in Python?如何获得有关 Python 代码覆盖率的增量报告?

By "incremental", I mean what has been the change in the covered lines since some "last" report, or from a particular Git commit.通过“增量”,我的意思是自某些“上次”报告或特定 Git 提交以来所涵盖行的变化。

I'm using unittest and coverage (and coveralls.io) to get the code coverage statistics, which work great.我正在使用unittestcoverage (以及coveralls.io)来获取代码覆盖率统计信息,这很好用。 But I'm involved only with a part of the project, and at first I'm concerned with what my last commit has changed.但是我只参与了项目的一部分,一开始我关心的是我最后一次提交的变化。 I expected coverage to be able to show the difference between two reports, but so far have not found anything short of running textual diff on HTML output.我希望coverage能够显示两个报告之间的差异,但到目前为止还没有发现除了在 HTML 输出上运行文本差异之外的任何内容。

Brief简介

I use pycobertura .我使用pycobertura

pycobertura diff --format html --output cov_diff.html coverage_old.xml coverage_new.xml


Details详情

I use the following chain ( coverage ):我使用以下链( coverage ):

  1. Generate coverage report: python -m coverage run -m unittest生成覆盖率报告: python -m coverage run -m unittest

  2. Output cobertura's XML format: coverage xml --omit tests/* -o cover_old.xml输出cobertura的XML格式: coverage xml --omit tests/* -o cover_old.xml

  3. -- Modify code or checkout newer commit -- -- 修改代码或签出较新的提交 --

  4. Generate coverage report: python -m coverage run -m unittest生成覆盖率报告: python -m coverage run -m unittest

  5. Output cobertura's XML format: coverage xml --omit tests/* -o cover_new.xml输出 cobertura 的 XML 格式: coverage xml --omit tests/* -o cover_new.xml

  6. Generate diff: pycobertura diff --format html --output cov_diff.html coverage_old.xml coverage_new.xml生成差异: pycobertura diff --format html --output cov_diff.html coverage_old.xml coverage_new.xml

I just posted an answer to similar question, it might help.我刚刚发布了类似问题的答案,它可能会有所帮助。 Compares previous run and current run.比较上次运行和当前运行。

show-the-differences-in-two-test-coverage-runs显示两次测试覆盖运行中的差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM