python - 覆盖率报告显示为零
问题描述
此代码与 calc.py 一起保存。这是一个基本的计算器程序,我在其中使用了烧瓶模块。
def sum(number1,number2):
result= number1+number2
return result
def sub(number1,number2):
result= number1-number2
return result
def mul(number1,number2):
result= number1*number2
return result
def div(number1,number2):
result= number1/number2
return result
该程序以 testing.py 名称保存在我的机器上。这里使用的模块是上面的 unitest 和 calc。我在这里做测试。因为我得到了 0% 的覆盖率报告。请帮帮我。如果可能,请对链接发表评论。
import unittest
import calc
class TestCalc(unittest.TestCase):
def test_sum1(self): # function to call self
#testing is being done for addition
result=calc.sum(10,15) #calculation module is being called
self.assertEqual(result,25)
print('test 1 of sum successful')
def test_sum2(self):# function to call self
#testing is being done for addition
result=calc.sum(12,7)#calculation module is being called
self.assertEqual(result,19)
print('test 2 of sum successful')
def test_sum3(self): # function to call self
#testing is being done for addition
result=calc.sum(15,5)#calculation module is being called
self.assertEqual(result,20)
print('test 3 of sum successful')
def test_sum4(self):# function to call self
#testing is being done for addition
result=calc.sum(12,8)#calculation module is being called
self.assertEqual(result,20)
print('test 4 of sum successful')
def test_sum5(self):# function to call self
#testing is being done for addition
result=calc.sum(10,15)#calculation module is being called
self.assertEqual(result,25)
print('test 5 of sum successful')
def test_sum6(self):# function to call self
#testing is being done for addition
result=calc.sum(10,15)#calculation module is being called
self.assertEqual(result,25)
print('test 6 of sum successful')
def test_sum7(self):# function to call self
#testing is being done for addition
result=calc.sum(10,15)#calculation module is being called
self.assertEqual(result,25)
print('test 7 of sum successful')
def test_sum8(self):# function to call self
#testing is being done for addition
result=calc.sum(12,7)#calculation module is being called
self.assertEqual(result,19)
print('test 8 of sum successful')
def test_sum9(self):# function to call self
#testing is being done for addition
result=calc.sum(10,15)#calculation module is being called
self.assertEqual(result,25)
print('test 9 of sum successful')
def test_sum10(self):# function to call self
#testing is being done for addition
result=calc.sum(12,7)#calculation module is being called
self.assertEqual(result,19)
print('test 10 of sum successful')
def test_sub1(self):# function to call self
#testing is being done for substraction
result=calc.sub(10,5)#calculation module is being called
self.assertEqual(result,5)
print('test 1 of sub successful')
def test_sub2(self):# function to call self
#testing is being done for substraction
result=calc.sub(12,7)#calculation module is being called
self.assertEqual(result,5)
print('test 2 of sub successful')
def test_sub3(self):# function to call self
#testing is being done for substraction
result=calc.sub(15,5)#calculation module is being called
self.assertEqual(result,10)
print('test 3 of sub successful')
def test_sub4(self):# function to call self
#testing is being done for substraction
result=calc.sub(12,8)#calculation module is being called
self.assertEqual(result,4)
print('test 4 of sub successful')
def test_sub5(self):# function to call self
#testing is being done for substraction
result=calc.sub(10,15)#calculation module is being called
self.assertEqual(result,-5)
print('test 5 of sub successful')
def test_sub6(self):# function to call self
#testing is being done for substraction
result=calc.sub(100,25)#calculation module is being called
self.assertEqual(result,75)
print('test 6 of sub successful')
def test_sub7(self):# function to call self
#testing is being done for substraction
result=calc.sub(15,5)#calculation module is being called
self.assertEqual(result,10)
print('test 7 of sub successful')
def test_sub8(self):# function to call self
#testing is being done for substraction
result=calc.sub(12,8)#calculation module is being called
self.assertEqual(result,4)
print('test 8 of sub successful')
def test_sub9(self):# function to call self
#testing is being done for substraction
result=calc.sub(10,15)#calculation module is being called
self.assertEqual(result,-5)
print('test 9 of sub successful')
def test_sub10(self):# function to call self
#testing is being done for substraction
result=calc.sub(100,25)#calculation module is being called
self.assertEqual(result,75)
print('test 10 of sub successful')
def test_mul1(self):# function to call self
#testing is being done for multiplication
result=calc.mul(2,4)#calculation module is being called
self.assertEqual(result,8)
print('test 1 of multiplication successful')
def test_mul2(self):# function to call self
#testing is being done for multiplication
result=calc.mul(6,2)#calculation module is being called
self.assertEqual(result,12)
print('test 2 of multiplication successful')
def test_mul3(self):# function to call self
#testing is being done for multiplication
result=calc.mul(15,5)#calculation module is being called
self.assertEqual(result,75)
print('test 3 of multiplication successful')
def test_mul4(self):# function to call self
#testing is being done for multiplication
result=calc.mul(12,8)#calculation module is being called
self.assertEqual(result,96)
print('test 4 of multiplication successful')
def test_mul5(self):# function to call self
#testing is being done for multiplication
result=calc.mul(10,15)#calculation module is being called
self.assertEqual(result,150)
print('test 5 of multiplication successful')
def test_mul6(self):# function to call self
#testing is being done for multiplication
result=calc.mul(5,5)#calculation module is being called
self.assertEqual(result,25)
print('test 6 of multiplication successful')
def test_mul7(self):# function to call self
#testing is being done for multiplication
result=calc.mul(15,5)#calculation module is being called
self.assertEqual(result,75)
print('test 7 of multiplication successful')
def test_mul8(self):# function to call self
#testing is being done for multiplication
result=calc.mul(12,8)#calculation module is being called
self.assertEqual(result,96)
print('test 8 of multiplication successful')
def test_mul9(self):# function to call self
#testing is being done for multiplication
result=calc.mul(10,15)#calculation module is being called
self.assertEqual(result,150)
print('test 9 of multiplication successful')
def test_mul10(self):# function to call self
#testing is being done for multiplication
result=calc.mul(5,5)#calculation module is being called
self.assertEqual(result,25)
print('test 10 of multiplication successful')
def test_div1(self):# function to call self
#testing is being done for division
result=calc.div(10,5)#calculation module is being called
self.assertEqual(result,2)
print('test 1 of division successful')
def test_div2(self):# function to call self
#testing is being done for division
result=calc.div(12,6)#calculation module is being called
self.assertEqual(result,2)
print('test 2 of division successful')
def test_div3(self):# function to call self
#testing is being done for division
result=calc.div(15,5)#calculation module is being called
self.assertEqual(result,3)
print('test 3 of division successful')
def test_div4(self):# function to call self
#testing is being done for division
result=calc.div(12,3)#calculation module is being called
self.assertEqual(result,4)
print('test 4 of division successful')
def test_div5(self):# function to call self
#testing is being done for division
result=calc.div(14,7)#calculation module is being called
self.assertEqual(result,2)
print('test 5 of division successful')
def test_div6(self):# function to call self
#testing is being done for division
result=calc.div(100,25)#calculation module is being called
self.assertEqual(result,4)
print('test 6 of division successful')
def test_div7(self):# function to call self
#testing is being done for division
result=calc.div(15,5)#calculation module is being called
self.assertEqual(result,3)
print('test 7 of division successful')
def test_div8(self):# function to call self
#testing is being done for division
result=calc.div(12,3)#calculation module is being called
self.assertEqual(result,4)
print('test 8 of division successful')
def test_div9(self):# function to call self
#testing is being done for division
result=calc.div(14,7)#calculation module is being called
self.assertEqual(result,2)
print('test 9 of division successful')
def test_div10(self):# function to call self
#testing is being done for division
result=calc.div(100,25)#calculation module is being called
self.assertEqual(result,4)
print('test 10 of division successful')
if __name__=='__main__':
unittest.main()
我收到 0% 的覆盖率报告,该怎么办??
解决方案
为了使用 unittest 运行覆盖率,只需运行
coverage run -m unittest discover
并且您正在导入一个不必要的导入
from flask import Flask,request,app
from flask import Flask,request
所以把它改成
from flask import Flask,request, app
推荐阅读
- javascript - CSS/JS 延迟加载背景图片(白色闪烁)
- regex - PowerShell 仅匹配首次出现的字符串
- c# - C# WPF - 如何将垂直滚动查看器放置在水平滚动查看器中
- python - mypy "'owclient' 的导入被忽略"
- r - 如何解决此错误以限制用户在 R 中输入的数据?
- php - 使用 Adobe Reader 在 Android 上的 Firefox 上,TCPDF 生成的 PDF 导致下载错误
- python - 为每个并行进程创建一个池
- php - ViewException:试图获取非对象的属性“跟随”
- flutter - 如何改变对话框 Flutter 的位置
- php - PHP; 将 CSV 导出到输出缓冲区:加载的文件为空。为什么?