仅适用于差异的Linting和coverage报告
diff-cov-lint的Python项目详细描述
差异cov lint
仅适用于git diff的Linting和coverage报告。在
用法:
diff-cov-lint master new_branch --cov_report=coverage.xml --lint_report=pylint_output.txt
输出示例(上面的命令在tests/repo
文件夹中运行):
======================== DIFF COVERAGE ========================
FILE COVERED STMTS PERCENT
src/add.py 5 8 62.5%
src/modify.py 1 2 50.0%
===============================================================
TOTAL DIFF COV 6 10 60.0%
========================== DIFF LINT ==========================
src/add.py:10:0 E0602: Undefined variable 'this_line_makes_no_sense' (undefined-variable)
参数:
位置参数TARGET_REF
回购中的目标分行SOURCE_REF
回购来源分行
标志--cov_report=COV_REPORT
Cobertura(pytest cov)格式的覆盖率报告路径,如果未声明,则不会生成覆盖率报告。--lint_report=LINT_REPORT
pylint报告的路径。如未注明,将不出具林绒报告。--repo_path=REPO_PATH
回购文件夹的路径,默认为“”
--show_missing
标志以显示缺少的行,默认为false
CI设置
这个项目的回购使用diff cov lint本身。您可能需要检查.gitlab-ci.yml的完整配置。在
简单场景
计算差异覆盖率并为合并请求生成diff-pylint报告
^{pr2}$更复杂的情况
- 对每个推送运行测试(测试作业)
- 计算差异覆盖率并为合并请求生成diff pylint报告(code_quality_diff job)
- 获取覆盖率和pylint报告的完整代码在主或手动推。(代码-质量-全部工作)
测试作业:
test:stage:testscript:-pytest --cov=your_source_folder --cov-report xml tests# run pytest and produce xml reportartifacts:paths:-coverage.xml# save xml report to use it in further jobsonly:-tags# tags and branches are default values of "only", so preserve them-branches-merge_requests# add merge_requests since code_quality_diff job will use artifacts of this job
差异代码质量作业:
code_quality_diff:stage:code_quality_diffscript:-git fetch -a# fetch all branches to calculate diff-pip install diff-cov-lint# install diff-cov-lint-pylint --exit-zero diff_cov_lint > pylint_output.txt# get pylint report. --exit-zero needed for job not to fail if pylint give score less than 10.-diff-cov-lint origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME --cov_report coverage.xml --lint_report pylint_output.txt# run diff-cov-lint on diff between target branch and source branch. coverage.xml is used from the artifact.only:-merge_requests
全代码质量作业:
code_quality_full:stage:code_quality_fullscript:-pytest --cov=your_source_folder tests# simply run pytest with coverage and pylint as usual-pylint --exit-zero diff_cov_lintrules:-if:'$CI_COMMIT_REF_NAME=="master"'-if:$CI_MERGE_REQUEST_IDwhen:never#otherwise this job will stuck for merge requests-when:manual# use manual to make this job optional for all other pipelines.
- 项目
标签: