如何更新覆盖率(包含在 pybuilder 中)以忽略 run.py 模块?

How to update coverage (that is inclued in pybuilder) to igrore run.py module?

问题:使用 Pybuilder 构建的 Flask 应用程序需要在构建过程中排除 run.py 覆盖率,以消除警告消息和对覆盖率百分比的影响

[WARN]  Module 'run' was not imported by the covered tests

[WARN]  Test coverage below 70% for run:  0%

(env3)$ python3 build.py
PyBuilder version 0.11.9
Build started at 2017-01-23 12:48:03
------------------------------------------------------------
[INFO]  Building myproject version 0.0.1.00526
[INFO]  Executing build in /Users/zzzz/Documents/Projects/myproject
[INFO]  Going to execute tasks: clean, install_dependencies, analyze, publish
[INFO]  Removing target directory /Users/zzzz/Documents/Projects/myproject/target
[INFO]  Installing all dependencies
[INFO]  Running unit tests
[INFO]  Executing unit tests from Python modules in /Users/zzzz/Documents/Projects/myproject/src/unittest/python
[INFO]  Executed 14 unit tests
[INFO]  All unit tests passed.
[INFO]  Executing flake8 on project sources.
[INFO]  Collecting coverage information
[WARN]  coverage_branch_threshold_warn is 0 and branch coverage will not be checked
[WARN]  coverage_branch_partial_threshold_warn is 0 and partial branch coverage will not be checked
[INFO]  Running unit tests
[INFO]  Executing unit tests from Python modules in /Users/zzzz/Documents/Projects/myproject/src/unittest/python
[INFO]  Executed 14 unit tests
[INFO]  All unit tests passed.
[WARN]  Module 'run' was not imported by the covered tests
------------------------------------------------------------
BUILD FAILED - Build aborted
------------------------------------------------------------
Build finished at 2017-01-23 12:48:16
Build took 12 seconds (12694 ms)
[WARN]  Test coverage below 70% for run:  0%
[WARN]  Test coverage below 70% for run:  0%
[WARN]  Test coverage below 70% for app.mod_upload: 21%
[WARN]  Test coverage below 70% for app.mod_upload: 21%
[INFO]  Overall coverage is 79%
[INFO]  Overall coverage branch coverage is 66%
[INFO]  Overall coverage partial branch coverage is 77%
[INFO]  Overall coverage is 79%
[INFO]  Overall coverage branch coverage is 66%
[INFO]  Overall coverage partial branch coverage is 77%
(env3)$ 

问题: 我本可以使用 answer here ,但是覆盖是由 pybuild 执行的,而不是我自己从命令行执行的,所以 --omit 解决方案不太适用,这造成了问题。有人可以指点一下吗?

找到答案了! 解决方案: 在 build.py(pybuilder 项目的一部分)中添加:

@init
def set_properties(project):
    project.set_property("coverage_exceptions", ['run',])

列表可以根据需要使用其他模块进行扩展。