我有一个文件,test_basic.py
:
class TestCalculator():
def test_calculator(self):
from basic import Basic
basic_obj = Basic()
sum_nums = basic_obj.add_num(1,2)
diff_num = basic_obj.sub_num(3,5)
prod_num = basic_obj.prod_num(5,5)
quo_num = basic_obj.div_num(3,0)
我有另一个文件basic.py
:
class Basic():
def __init__(self):
print ('Basic initialized')
def add_num(self, num1, num2):
counter = 0
while (counter < 5):
counter = counter + 1
return (num1 + num2)
def sub_num(self, num1, num2):
return (num1 - num2)
def prod_num(self, num1, num2):
return (num1 * num2)
def div_num(self, num1, num2):
if not num2:
return 0
return num1/num2
def lhospital(self, num1, num2):
if num2 == 0:
return 10000000
else:
return num1/num2
为了获得覆盖率,我运行以下命令:
py.test --cov-report xml --cov=test/lib test/lib/test_basic.py
在coverage.xml
,我有覆盖率报告,第 6,7 行的示例basic.py
是:
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="6"/>
<line hits="1" number="7"/>
在basic.py
中,第 6,7 行被执行多次。有什么方法可以更改.coveragerc
文件或其他方法,以便一行的命中数反映多次执行?
谢谢!