在Python coverage.py API中使用省略标志 [英] Using omit flag in Python coverage.py API

查看:146
本文介绍了在Python coverage.py API中使用省略标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python coverage.py创建一个具有覆盖率的非常基本的测试套件。目前,一切正常。但是,我的覆盖率报告包括所有被调用的 / usr / local / lib 库和所有 __ init __。py 文件。

I'm using the python coverage.py to create a very basic test suite with coverage. Currently everything works great. However, my coverage report includes all the /usr/local/lib libraries that are called and all the __init__.py files.

这是我的覆盖率报告现在的样子:

Here's what my coverage report call looks like right now:

self.cov.html_report(directory='coverage', omit='*Test*, */usr/local/lib*,*__init__*')

目标是使用省略标志来删除其中包含单词 Test, / usr / local / lib或 __init__的所有类。由于在Web上我在API上找不到太多的东西(在命令行上有很多关于它的方法),有人知道做这项工作的正确语法是什么吗?

The goal is to use the omit flag to remove all classes with the word "Test", "/usr/local/lib", or "__init__" in them. Since I can't find too much on the web about this in the API (There's plenty about how to do it on the command line), does someone know what the correct syntax to make this work would be?

推荐答案

尝试在coverage()调用中省略不需要的文件:

Try ommiting unwanted files in the coverage() call:

self.cov = coverage.coverage(omit=['*Test*', '*/usr/local/lib*','*__init__*'])

我会使用coverage配置文件(默认值为.coveragerc)进行命令:

I would recommand using the coverage config file (default is .coveragerc):

# .coveragerc to control coverage.py

[run]
omit =
        *__init__*
        */usr/local/lib*
        *Test*

[html]
omit =
        *__init__*
        */usr/local/lib*
        *Test*

默认情况下,coverage调用会考虑.coveragerc文件,但如果要确保使用:

The coverage call takes the .coveragerc file into consideration by default, but if you want to make sure use:

self.cov = coverage.coverage(config_file=True)

或者,您可以更改配置文件名并将其作为参数传递:

Alternatively, you can change the config file name and pass it as an argument:

self.cov = coverage.coverage(config_file='/your/path/.coverage_config_file')

希望这会有所帮助。

这篇关于在Python coverage.py API中使用省略标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆