Invalid coverage report when using 2 with in python 2.6

Issue #319 duplicate
Matteo Kloiber
created an issue

What is the problem

When using 2 with statements, the coverage report doesn't reach 100%. The HTML report shows an partial error:
Screen Shot 2014-07-17 at 6.56.54 PM.png

Do you have a testcase for me?

Of course I do:

class TestSomething(unittest.TestCase):
    def testMe(self):
        with mock.patch("os.access") as AccessMock:
            AccessMock.return_value = True

            with mock.patch("os.path.join") as JoinMock:
                JoinMock.return_value = "/test/hello"

                self.assertEquals("/test/hello", os.path.join("/test", "hello"))
                self.assertTrue(os.access("test"))

            blah = "Some other test"
            self.assertEquals("Some other test", blah)

            print "There is no exit!"


if __name__ == "__main__":
    unittest.main()

I used coverage erase; coverage run --branch --source tests tests/test.py -v; coverage report; coverage html to execute the testcase. (Make sure you have the latest version of mock installed).
The output is:

$ coverage erase; coverage run --branch --source tests tests/test.py -v; coverage report; coverage html
testMe (__main__.TestSomething) ... There is no exit!
ok

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK
Name                   Stmts   Miss Branch BrMiss  Cover
--------------------------------------------------------
tests/__init__             0      0      0      0   100%
tests/test                14      0      2      1    94%

What version are affected

Coverage 3.7.1 (maybe below, I didn't test it).
Python 2.6 (Python 2.7 works, I couldn't test it on Python 3+)

Although I don't think it is OS specific, I've tested it on Mac OS X Mavericks (10.9) and Yosemite (10.10).

Comments (3)

  1. Log in to comment