1

我用许多应用程序构建了 django 项目。现在我想为这些应用程序生成一个覆盖率报告。出于测试目的,我使用 py.test、pytest-django 和 pytest-cov。到目前为止,我只能通过在命令行上手动输入所有应用程序名称来生成报告:

py.test --cov-report html --cov=app1 --cov=app2 --cov=app3 --cov=app4 */tests.py

pytest-cov 有没有办法用一个简单的表达式来指定所有的应用程序?

4

3 回答 3

4

假设您使用的是 bash,您可以使用它来扩展参数:

py.test --cov-report html --cov=app{1,2,3,4} */tests.py

您还可以添加这些参数,pytest.ini以便在每次调用时自动传递它们。

于 2016-04-23T16:46:55.113 回答
2

@the-compiler 的答案对我不起作用。如果您想测试所有应用程序,可以使用以下方法:

pytest --cov-report html --cov=. */tests.py

来源:https ://medium.com/@harshvb7/using-pytest-to-write-tests-in-django-6783674c55b8

于 2018-10-16T08:57:04.177 回答
0

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在pytest.ini中更改此行

python_files = tests.py test_*.py */tests_*.py

在此处输入图像描述

coverage run -m pytest
于 2022-02-07T16:10:16.217 回答