如何知道Django应用程序的覆盖范围?

2024-05-18 20:53:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的django项目,其中包含一些应用程序。一切作品好吧。现在如何检查我的项目的代码覆盖率。我已经安装了coverge-3.5工具,并试图通过从终端输入“coverage report”来了解覆盖率

NAME----->;(我项目中的某个文件)

STMS----->;(一些数字)

小姐——————(一些数字)

覆盖率------>;(部分%)

在我的例子中,它将显示一些结果,只显示来自项目。It没有显示我的所有文件的覆盖范围项目。怎么做我要显示我所有的文件名吗????在

请建议任何更好的工作覆盖工具,如果你知道!


Tags: 文件工具项目django代码namegtreport
3条回答

我设法用django_coverage和django_nose解决了这个问题

我在已安装的应用程序中添加了“django_coverage”和“django_nose”

穿上这个设置.py在

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

# Tell nose to measure coverage on the 'foo' and 'bar' apps
NOSE_ARGS = [
    ' with-coverage',
    ' cover-package=schedule',
]

安装它

pip install django_coverage

How do I use it?

Install as a Django app Place the entire:

django_coverage app in your third-party apps directory.

Update your settings.INSTALLED_APPS to include django_coverage.

Include test coverage specific settings in your own settings file.

See settings.py for more detail. Once you've completed all the steps, you'll have a new custom command available to you via manage.py test_coverage.

It works just like manage.py test.

Use it as a test runner

You don't have to install django_coverage as an app if you don't want to. You can simply use the test runner if you like. Update settings.TEST_RUNNER = 'django_coverage.coverage_runner.CoverageRunner' Include test coverage specific settings in your own settings file. See settings.py for more detail. Run manage.py test like you normally do.

首先确保您使用的是最新的覆盖版本。你所能做到的: 假设您的django项目位于project\u parent/project下,从project\u parent运行:

coverage html  include=project/*.*

这将只给你一个项目的覆盖率报告(即不输出第三方lib覆盖率)

我就是这样工作的:

coverage run  source=app1,app2 ./manage.py test  settings=path.to.test_settings app1,app2

我不认为这是我们想要的方法,因为我们不使用/管理.py测试覆盖率命令,但我找不到其他方法。在

相关问题 更多 >

    热门问题