python - 测试目录中 python3 Flask、unittest 和 cntext.py 中的覆盖率报告未涵盖的行
问题描述
当我在运行我测试过的方法中的任何行coverage report -m
之后运行命令时,我使用一个文件并且我有以下项目结构coverage run main.py
context.py
my_project
├── service
│ ├── __init__.py
│ └── setThings.py
└── test
├── context.py
├── __init__.py
└── test_setThings.py
这是我的 context.py 的内容
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import service
from service import setThings
这是我的服务 setThings.py
from jinja2 import Environment, FileSystemLoader
def check_if_json_property_is_null(json_property):
if(json_property != ""):
return json_property
else:
return " "
这是我的测试文件
import unittest
import json
from collections import namedtuple
from .context import setThings
class Test_SetThings(unittest.TestCase):
def test_given_none_property_when_checking_if_none_return_empty(self):
#ASSERT
self.assertEqual(" ", setThings.check_if_json_property_is_null(""))
if __name__ == '__main__':
unittest.main()
所以在我运行coverage report -m
它之后说我的服务方法中的行没有被覆盖,我在我的需求文件中使用了coverage==4.5.3,
另外我正在从项目根目录运行所有命令
解决方案
推荐阅读
- docker - Docker 请求对资源的访问被拒绝
- javascript - 从 Vue.js 中的组件更改父级的布局
- python - 如何在我的 Django 项目中设置唯一的邮件注册?
- android - 从 Firestore 加载标记的最佳方式
- c++ - BSTR 分配混乱
- php - 在 WooCommerce 简单产品的添加到购物车按钮中显示可用性
- c# - 页面重新加载时图像不断消失
- javascript - 我找不到在某个 PDO 实例中提交此复选框循环结果的方法
- pandas - 如何使用 Dask 正确迭代 for 循环?
- python-3.x - Kinesis GetRecords API 返回空 Records[] 数组