gpt4 book ai didi

python - pytest 覆盖率 - 一行的命中数

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:52 26 4
gpt4 key购买 nike

我有一个文件,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中,我有覆盖率报告,basic.py中第6,7行的示例是:

<line branch="true" condition-coverage="100% (2/2)" hits="1" number="6"/>
<line hits="1" number="7"/>

basic.py中,第6,7行被执行多次。有没有办法更改 .coveragerc 文件或其他文件,以便一行的命中数反射(reflect)多次执行?

谢谢!

最佳答案

Coverage.py 不支持点击计数。也许将来会。

关于python - pytest 覆盖率 - 一行的命中数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47031270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com