Reputation: 11
I have a problem with coverity data in report, it doesn't agree. Or is it just the way it works? My example. File functions.py:
class TestClass(object):
def __init__(self, a, b, c, d):
self.a = a
self.b = b
self.c = c
self.d = d
File tests.py:
def testClassInit():
instance = functions.TestClass(a=1, b=2, c=3, d=4)
assert instance.a == 1
assert instance.b == 2
The report shows that all lines in functions.py file are covered what it is not the truth, self.c and self.d aren't.
When I do:
def testClassInit():
instance = functions.TestClass(a=1, b=2, c=3, d=4)
assert instance.a == 1
assert instance.b == 2
assert instance.c == 3
assert instance.d == 4
the coverage is the same. Can sb explain it to me?
BTW. Is it ok to use so many asserts in on test in this case?
Upvotes: 1
Views: 1182
Reputation: 375744
Coverage doesn't measure whether you have the right asserts. It measures whether lines were executed. In your first test, all of the lines in your __init__
method are executed. In fact, they are all executed by the first line of your test. The asserts are irrelevant in this case.
As an aside, it's fine to have many asserts in one test, so long as they are all about a single outcome.
Upvotes: 1
Reputation: 2382
Coverage report is simply telling you which lines were executed during test. So all four lines in your init() will be executed when you create an instance of the class.
Upvotes: 0