我用许多应用程序构建了 django 项目。现在我想为这些应用程序生成一个覆盖率报告。出于测试目的,我使用 py.test、pytest-django 和 pytest-cov。到目前为止,我只能通过在命令行上手动输入所有应用程序名称来生成报告:
py.test --cov-report html --cov=app1 --cov=app2 --cov=app3 --cov=app4 */tests.py
pytest-cov 有没有办法用一个简单的表达式来指定所有的应用程序?
我用许多应用程序构建了 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