- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力实现 100% 的覆盖率。
我有文件 (app/ifaces.py):
import netifaces
class NoIPException(Exception):
pass
def get_local_ips():
...(code here)
我有测试:
import pytest
import mock
import netifaces
from app import ifaces
def test_get_local_ips_normal_case():
....
当我手动运行测试时:
py.test -v --cov app --cov-report term-missing
它报告 100% 的代码覆盖率: 应用程序/ifaces 16 0 100%
但是当我将它作为“自运行”添加到测试中时,它报告前六行未被覆盖:
if __name__ == "__main__":
import sys
pytest.main("-v %s --cov app/ifaces.py --cov-report term-missing" % sys.argv[0])
报告:
Name Stmts Miss Cover Missing
--------------------------------------------
app/ifaces 16 4 75% 1-6
如何添加自运行测试以获得与手动 py.test 执行相同的结果?结果之间有什么区别?为什么 app/ifaces.py 中的 6 行被报告为在第二种情况下未涵盖?
谢谢。
最佳答案
好吧,我找到了一个原因。
当从测试本身调用 pytest 时,所有导入都已完成,因此,它们不计入已覆盖。
为了覆盖它们,需要在 pytest-cov 执行期间导入它们。
我的解决方案是使用 pytest fixtures 进行导入:1. 从测试程序的顶部删除“from app import ifaces”。2. 添加 fixture :
@pytest.fixture
def ifaces():
from app import ifaces
return ifaces
3.让它可以作为变量通过测试:
def test_get_local_ips_normal_case(ifaces)
....
关于python - 使用 pytest-cov 的类声明缺少测试覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34882426/
当我尝试通过命令行运行测试时 py.test file_name.py 我收到了这个错误: py.test: error: unrecognized arguments: --cov=ner_bra
我在下面运行这个测试用例命令 py.test --cov-report term-missing --cov=pipelines/core/comp/plugins/abc/ --noconftest
我在下面运行这个测试用例命令 py.test --cov-report term-missing --cov=pipelines/core/comp/plugins/abc/ --noconftest
这个问题可能很愚蠢,但我找不到对此的解释。 我正在从头开始编写多元概率密度函数(用于研究目的),我需要计算的其中一件事是数据的协方差矩阵。我正在使用 Iris 数据集(150 个样本,4 个特征),当
我有以下目录结构: ./ src/ tests/ unit/ integration/ 我想使用 pytest 在 unit/ 和 integratio
我正在使用 py.test 使用 python 请求库进行 REST API 自动化。 如何使用 pytest-cov 工具获得覆盖率。我在构建服务器上运行自动化,代码在应用程序服务器中执行。 最佳答
我用很多应用程序构建了 django 项目。现在我想为这些应用程序生成一份覆盖率报告。出于测试目的,我使用 py.test、pytest-django 和 pytest-cov。到目前为止,我只能通过
我用很多应用程序构建了 django 项目。现在我想为这些应用程序生成一份覆盖率报告。出于测试目的,我使用 py.test、pytest-django 和 pytest-cov。到目前为止,我只能通过
我是Python和线性代数的新手,我有一个关于矩阵协方差的问题。 我有一个 21 x 2 矩阵,其中第一列代表当年发布的视频游戏的平均得分(从 0 到 10),第二列代表从 1996 年到 2016
我有一个 X 数据集,其中有 9 个特征和 683 行 (683x9)。我想获取此 X 数据集和另一个与 X 形状相同的数据集的协方差矩阵。我使用 np.cov(originalData, gener
我正在尝试为我的程序运行 py.test cov,但我仍然有一条信息:testFile.txt sCoverage.py 警告:未收集数据。即使在代码中仍然是未经测试的函数(在我的示例函数 diff
我有自己的基于等式的协方差函数的实现: ''' Calculate the covariance coefficient between two variables. ''' import numpy
我开始使用 llvm-cov 为我的项目生成覆盖统计数据。 llvm-cov有几类:行覆盖、函数覆盖和区域覆盖。但是他们都只考虑实例化的函数,没有实例化的函数会被简单地忽略。这样,对于实例化函数百分比
背景 我是使用 pytest 和 pytest-cov 的新手,从 unittest + coverage.py 切换过来 我首先将我的自动化测试设置为以这种方式运行:python3 -m pytes
我的项目中有 2 个文件(a.py 和 b.py)。 a.py 文件被导入到单元测试文件 (test_prog.py) 中,并且有为其编写的测试。 Pytest-cov 显示此文件的覆盖范围。 但是,
我已经下载了 coverity 构建工具 - cov-analysis-macosx-2019.03我已将“bin”目录添加到路径变量中。我可以访问下面的 coverity 命令。Nanthakuma
我试图实现numpy.cov()函数,如下所示:numpy cov (covariance) function, what exactly does it compute? ,但我得到了一些奇怪的结果
来自llvm-cov docs : llvm-cov show [options] -instr-profile PROFILE BIN [-object BIN,...] [[-object BIN
我正在努力实现 100% 的覆盖率。 我有文件 (app/ifaces.py): import netifaces class NoIPException(Exception): pass d
我有以下头文件: 电源.hpp: #pragma once #include template () * std::declval())> constexpr inline R square(con
我是一名优秀的程序员,十分优秀!