pytest-cov 一次涵盖许多应用程序

pytest-cov cover many applications at once

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

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

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

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

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

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

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

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

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

之前

之后

pytest.ini

中更改此行
python_files = tests.py test_*.py */tests_*.py

coverage run -m pytest