相关疑难解决方法(0)

使用coverage,如何测试此行?

我有一个简单的测试:

class ModelTests(TestCase):

    def test_method(self):
        instance = Activity(title="Test")
        self.assertEqual(instance.get_approved_member_count(), 0)
Run Code Online (Sandbox Code Playgroud)

我的问题是覆盖仍然显示未get_approved_member_count测试的行:

在此输入图像描述

我如何满足上述覆盖范围?

要运行测试我正在使用Django Nose和Coverage:

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

NOSE_ARGS = [
    '--with-coverage',
    '--cover-html',
    '--cover-package=apps.users,apps.activities',
]
Run Code Online (Sandbox Code Playgroud)

安慰:

python manage.py test
/Users/user/Documents/workspace/api/env/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
  return f(*args, **kwds)

/Users/user/Documents/workspace/api/env/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated in favor of the new application loading system.
  return f(*args, **kwds)

nosetests --with-coverage …
Run Code Online (Sandbox Code Playgroud)

python django django-testing

15
推荐指数
1
解决办法
403
查看次数

标签 统计

django ×1

django-testing ×1

python ×1