问题标签 [pytest-cov]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1713 浏览

python - 对于带有 pytest-cov 的 pytest:如何为覆盖版本 >= 5 指定 parallel=True

pytest-cov 文档中它说:

请注意,此插件控制一些选项,在配置文件中设置选项将无效。其中包括指定要测量的源(源选项)和所有数据文件处理(data_file 和并行选项)。

但是它没有说明如何更改这些选项。有没有办法改变它(平行=真)?我想更改它,因为在覆盖范围从 < 5 升级到最新 (5.1) 后,我得到了这些:

注意:使用coverage < 5没有这个问题

我也尝试使用以下内容添加.coveragerc但仍然遇到相同的问题。

它在jenkins中运行的方式:

0 投票
0 回答
143 浏览

docker - pytest-cov ERROR 导入文件不匹配导致heroku存储库中的旧目录,无法删除目录

在 testdriven.io 上使用 Django、Django REST 框架和 Docker 进行的测试驱动开发课程在 pytest-cov 部分之前进展顺利。我的错误是在开始之前我做了一个 Heroku 教程,目录被卡住了。

更新容器

$ docker-compose up -d --build

然后

然后我尝试删除 alpinehelloworld/

然后

该目录仍然存在:(我如何删除/usr/src/app/alpinehelloworld/webapp/tests.py

0 投票
1 回答
1172 浏览

python - 除非在其中一个单元测试中导入,否则 Pytest-cov 不考虑文件进行覆盖率分析?

我的项目中有 2 个文件(a.pyb.py)。a.py文件被导入到单元测试文件 ( test_prog.py) 中,并且为它编写了测试。Pytest-cov 显示了这个文件的覆盖率。

但是对于另一个文件b.py- 它在代码覆盖率输出中看不到。除非在其中一个单元测试中导入,否则 Pytest-cov 不考虑文件进行覆盖率分析?

0 投票
2 回答
20641 浏览

python - How to get coverage reporting when testing a pytest plugin?

Context

I am updating an inherited repository which has poor test coverage. The repo itself is a pytest plugin. I've changed the repo to use tox along with pytest-cov, and converted the "raw" tests to use pytester as suggested in the pytest documentation when testing plugins.

The testing and tox build, etc. works great. However, the coverage is reporting false misses with things like class definitions, imports, etc. This is because the code itself is being imported as part of pytest instantiation, and isn't getting "covered" until the testing actually starts.

I've read pytest docs, pytest-cov and coverage docs, and tox docs, and tried several configurations, but to no avail. I've exhausted my pool of google keyword combinations that might lead me to a good solution.

Repository layout

Some relevant snippets with commentary:

tox.ini

This configuration gives me an error that no data was collected; no htmlcov is created in this case.

If I just use --cov, I get (expected) very noisy coverage, which shows the functional hits and misses, but with the false misses reported above for imports, class definitions, etc.

conftest.py

test_my_plugin.py


How can I get an accurate report? Is there a way to defer the plugin loading until it's demanded by the pytester tests?

0 投票
1 回答
722 浏览

python - Pytest 和 pytest-cov 引发 CoverageException

使用 Pytest + Pytest-cov 执行我的测试套件后,我收到以下错误:

coverage.misc.CoverageException:无法使用数据文件“/usr/local/myappname/.coverage”:看起来像覆盖率 4.x 数据文件。你在混合不同的覆盖范围吗?

这很奇怪,因为在我的本地开发环境中失败但在测试环境中工作正常并且配置没有变化。

0 投票
1 回答
1098 浏览

python - 为什么不使用 starlettes TestClient 使用 pytest-cov 获得 100% 的 FastAPI 覆盖率

我根本不明白 pytest-cov 的输出

在此处输入图像描述

我的测试模块如下

即我不理解 1 部分和 1 缺失。完整的 CLI 报告:

我首先想了解丢失267, 10->9的内容-该文件中的行数甚至不超过 15 行。这可能也可以解释剩下的问题。

0 投票
0 回答
64 浏览

python - pytest-ordering order 模块不是模块内的测试用例

我有一个不同模块中的测试用例列表(此处仅显示一瞥,但实际上计数约为 10)。我希望 pytest 按顺序执行这些模块,第一个 module-a.py,下一个 module-b.py 等等......但是,我知道在模块中排序测试用例,它工作得很好。

我们的整个应用程序是一种管道,其中模块-a 的输出由模块-b 等消耗。我们希望按照定义的模块顺序完全端到端地测试它。

从上面的代码中,我希望依次执行 module-a test_four、test_three module-b test_one、test_two。

目前,我们正在使用 --cov-append 运行每个模块,如下所示并生成最终覆盖率。

任何人都可以帮助更好的方法或更好的方法。

0 投票
1 回答
684 浏览

bitbucket - 提交拉取请求时完成的 Pytest + 覆盖回归测试(天蓝色管道和 bitbucket)

我在 bitbucket 存储库中有一个 python 包。我想设置 azure 管道,以便当我向该存储库的主分支提交拉取请求时,会运行一堆 pytest 测试。

除此之外(单独或最好在 pytest 测试套件本身中)我希望运行覆盖测试,并且如果主分支的覆盖百分比高于分支的覆盖百分比,则该测试失败正在被合并到它是。

这个想法是除非测试覆盖率增加,否则无法合并拉取请求。

有谁知道我该怎么做?

0 投票
0 回答
399 浏览

python - 如何在python烧瓶中模拟redis会话

我正在尝试使用pytest. 该应用程序使用 Redis 来存储变量。使用该变量,应用程序可以确定某些操作。

这是我要测试的几个代码app.py

IF问题是测试完全运行,没有错误,但是or函数下的其余部分else不包括测试

我试过在我的test_app.py

0 投票
1 回答
4378 浏览

python - Pytest cov 不读取 pyproject.toml

Pytest cov 没有从 pyproject.toml 文件中读取其设置。我正在使用 nox,所以我运行测试:

即使没有nox,我似乎也有同样的问题。

事实上,在运行之后poetry install

  • poetry run pytest --cov=src通过测试
  • poetry run pytest --cov没有通过测试

特别是,当测试失败时,我有以下输出(输出被削减到最重要的东西):

此处有可重现错误的代码。要运行它,您需要安装诗歌安装 nox