想象一下您有一个 BASE_CLASS
的情况。几个类继承自该类:CHILD_A
、CHILD_B
、CHILD_C
。
现在让我们编写单元测试,但仅限于 CHILD_A
、CHILD_B
、CHILD_C
。我怀疑 BASE_CLASS
的覆盖率是 0%。不幸的是,nose
需要累积覆盖,这不是我想要的。我尝试在执行测试时使用 ---cover-erase
标志,但这没有帮助。
我的问题是:如何强制 nose
不使用累积覆盖率?我需要这个来了解 BASE_CLASS
的单元测试有多好。
最佳答案
您的测试正在运行 BASE_CLASS
中的代码。 Python 在创建子类实例时不仅仅知道基类中有什么。它必须转到基类并查看那里的代码。
如果您想了解您对特定基类的覆盖率,您可以运行特定于该类的测试用例/方法。来自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
关于python - Nose 报告累积覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31003273/