gpt4 book ai didi

python - 警告 : Failed to generate report: No data to report error in python using pytest module

转载 作者:行者123 更新时间:2023-12-04 12:07:08 61 4
gpt4 key购买 nike

示例.py代码:

def sum(num1, num2):
return num1 + num2


def sum_only_positive(num1, num2):
if num1 > 0 and num2 > 0:
return num1 + num2
else:
return None

test_sample.py code

from . import sample

import pytest

def test_sum():
assert sample.sum(5, 5) == 10

def test_sum_positive_ok():
assert sample.sum_only_positive(2, 2) == 4

def test_sum_positive_fail():
assert sample.sum_only_positive(-1, 2) is None

覆盖命令: pytest test_sample.py --cov=sample.py
错误:
platform linux -- Python 3.5.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/apathapa/unit_test/warriorframework_py3
plugins: cov-2.8.1
collected 3 items

test_sample.py ... [100%]Coverage.py warning: Module sample.py was never imported. (module-not-imported)
Coverage.py warning: No data was collected. (no-data-collected)
WARNING: Failed to generate report: No data to report.

/home/apathapa/ut/lib/python3.5/site-packages/pytest_cov/plugin.py:254: PytestWarning: Failed to generate report: No data to report.

self.cov_controller.finish()


----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name Stmts Miss Cover
---------------------------


============================================================= 3 passed in 0.13s ==============================================================

谁能帮我解决这个错误?

最佳答案

--cov接受目录或包名,而不是单个文件。这意味着 --cov=sample.py查找名为 sample 的包(目录)在其中,一个名为 py.py 的模块(文件)记录覆盖率,但失败了。要么使用

$ pytest --cov=sample

或者
$ pytest --cov=.

关于python - 警告 : Failed to generate report: No data to report error in python using pytest module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60776736/

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