久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用nosetests從python覆蓋率報告中排除模擬包

How to exclude mock package from python coverage report using nosetests(如何使用nosetests從python覆蓋率報告中排除模擬包)
本文介紹了如何使用nosetests從python覆蓋率報告中排除模擬包的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前嘗試使用mock庫在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]

有什么方法可以排除 mock 包和 imaplib 包而無需通過 --cover-package=PACKAGE

Is there any way to exclude the mock package and the imaplib package without having to manually whitelisting all but those packages by --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.

如果有幫助,我使用 Coverage.py,版本 3.5.2.

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

推薦答案

創建一個 .coveragerc 文件,在報告中排除您不想要的內容:http://nedbatchelder.com/code/coverage/config.html

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

這篇關于如何使用nosetests從python覆蓋率報告中排除模擬包的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 91久久精 | 一区二区三区国产 | 色综合桃花网 | 天堂资源最新在线 | av网址在线播放 | 伊人网站 | 精品久久国产 | 国产精品色 | 超碰97在线免费 | 久久精品国产亚洲夜色av网站 | 密室大逃脱第六季大神版在线观看 | 成年人国产在线观看 | 理论片87福利理论电影 | 亚洲天堂一区二区 | www.成人在线视频 | 天天综合网天天综合色 | 欧美激情一区 | 国产精品久久久久无码av | 日韩三区在线观看 | 久久久国产精品视频 | 欧美精品二区 | av片在线观看 | 干干干操操操 | 网站一区二区三区 | 成人一级毛片 | 激情三区 | 久久美女网 | 成人午夜激情 | 亚洲一二三在线 | 国产精品久久久久久影院8一贰佰 | 午夜精品久久久久久久星辰影院 | 久久亚洲一区 | 日韩精品区| 日本在线视频一区二区 | 国产精品免费高清 | 亚洲精品久久久一区二区三区 | 久久国产精品免费一区二区三区 | 久久宗合色 | 伊人久久成人 | 中文字幕 亚洲一区 | 一区二区三区国产精品 |