Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:59:53+00:00 2026-06-10T12:59:53+00:00

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

  • 0

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

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?

Here is the class I want to test:

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")

I now get the following output for 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]

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

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

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.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:59:54+00:00Added an answer on June 10, 2026 at 12:59 pm

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently try to use Reachability in iOS 5.1 on iPad. There is a
Im currently facing the problem that when i try to set focus on some
I am currently using two catch blocks after a try block. The first catches
I have started to try out noSQL databases now and are currently testing out
Currently I try to use: wget --user=xxx --password=xxx -r ftp://www.domain.com/htdocs/ But this saves output
I am currently working on some OSGi application and I wanted to use the
i currently try to import some XML via XMLSimple in my RoR-3 App. on
I am currently using ipython. When I try to use the well-known magic function
I try to use jqplot for drawing an graph. So i modified this example
I currently try to write a program for the VFP unit of the iPhone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.