如何使用鼻子测试将模拟包从python覆盖率报告中排除

编程入门 行业动态 更新时间:2024-10-25 13:29:52
本文介绍了如何使用鼻子测试将模拟包从python覆盖率报告中排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前尝试使用模拟库在python中编写一些基本的鼻子单元测试.

I currently try to use the mock library to write some basic nose unittests in python.

完成一些基本示例后,我现在尝试使用nosetests --with-coverage,现在我有了模拟程序包,并且尝试模拟"的程序包显示在覆盖率报告中.有可能排除这些吗?

After finishing some basic example I now tried to use nosetests --with-coverage and now I have the mock package and the package I tried to 'mock away' are shown in the coverage report. Is there a possibility to exclude these?

这是我要测试的课程:

from imaplib import IMAP4 class ImapProxy: def __init__(self, host): self._client = IMAP4(host)

和测试用例: 从模拟导入补丁

And the testcase: from mock import patch

from ImapProxy import ImapProxy class TestImap: def test_connect(self): with patch('ImapProxy.IMAP4') as imapMock: proxy = ImapProxy("testhost") imapMock.assert_called_once_with("testhost")

我现在得到nosetests --with-coverage

. Name Stmts Miss Cover Missing ------------------------------------------ ImapProxy 4 0 100% imaplib 675 675 0% 23-1519 mock 1240 810 35% [ a lot of lines]

是否可以通过--cover-package=PACKAGE

感谢Ned Batchelder我现在了解.coveragerc文件,谢谢!!

Thanks to Ned Batchelder I now know about the .coveragerc file, thanks for that!

我创建了一个.coveragerc文件,其内容如下:

I created a .coveragerc file with the following content:

[report] omit = *mock*

现在,我在覆盖率报告中的模拟输出为:

Now my output for mock in the coverage report is:

mock 1240 1240 0% 16-2356

它不再涵盖模拟包,但仍在报告中显示.

It does not cover the mock package any longer but still shows it in the report.

如果有帮助,我会使用3.5.2版的Coverage.py.

I use Coverage.py, version 3.5.2 if this is any help.

推荐答案

创建一个.coveragerc文件,该文件排除了报告中不需要的内容: nedbatchelder/code/coverage/config.html

Create a .coveragerc file that excludes what you don't want in the report: nedbatchelder/code/coverage/config.html

更多推荐

如何使用鼻子测试将模拟包从python覆盖率报告中排除

本文发布于:2023-11-04 12:22:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:覆盖率   如何使用   鼻子   测试   报告

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!