首页 文章

鼻子报告累积报道

提问于
浏览
0

想象一下你有一个 BASE_CLASS 的情况 . 几个类继承自该类: CHILD_A ,_ _ 28527278, CHILD_C .

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

我的问题是:如何强制 nose 不使用累积保险?我需要知道 BASE_CLASS 的单元测试有多好 .

1 回答

  • 1

    您的测试正在运行 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
    

相关问题