鼻子报告累积覆盖率

nose reports cumulative coverage

想象一下你有 BASE_CLASS 的情况。几个 class 继承自那个 class:CHILD_ACHILD_BCHILD_C

现在让我们编写单元测试,但仅限于 CHILD_ACHILD_BCHILD_C。我怀疑 BASE_CLASS 的覆盖率是 0%。不幸的是,nose 需要累积覆盖,这不是我想要的。我在执行测试时尝试使用 ---cover-erase 标志,但这没有帮助。

我的问题是:如何强制 nose 不使用累积覆盖?我需要这个来了解 BASE_CLASS.

的单元测试有多好

您的测试正在 运行 测试 BASE_CLASS 中的代码。 Python 在创建子 class 实例时不仅仅知道基础 class 中的内容。它必须去基地 class 并查看那里的代码。

如果您想了解您对特定基础 class 的覆盖率,您可以 运行 特定于该 class 的测试 case/method。来自 docs:

# Run all the tests in the animals.tests module
$ ./manage.py test animals.tests

# Run all the tests found within the 'animals' package
$ ./manage.py test animals

# Run just one test case
$ ./manage.py test animals.tests.AnimalTestCase

# Run just one test method
$ ./manage.py test animals.tests.AnimalTestCase.test_animals_can_speak