简体   繁体   English

Nosetest覆盖范围未显示以Test开头的类

[英]Nosetest coverage not showing classes starting with Test

Im generating a coverage report with nosetest using the following command: 我使用以下命令使用鼻子测试生成覆盖报告:

nosetests --exe --with-coverage --cover-html --cover-package=Mypackage Tests/

In my tests Im using some classes and almost all classes are found except one thats called: 在我的测试中,Im使用了一些类,几乎找到了所有类,除了那些称为:

TestCasesFilter

After trying some thigns I found out that when I rename the class to something else eg OneTestCasesFilter the class is added to the coverage report. 经过一番尝试,我发现当我将该类重命名为其他名称时,例如OneTestCasesFilter,该类将添加到覆盖率报告中。 Our naming convention requires us to name the class after the table in the datbase that is written to so in this case TestCases. 我们的命名约定要求我们在写入的datbase表之后命名该类,在这种情况下为TestCases。 Is it possible to add the class to the coverage report without renaming the class? 是否可以在不重命名课程的情况下将课程添加到覆盖率报告?

Im using: 我正在使用:

python 2.7.14
coverage 4.4.1
nose 1.3.7

Background 背景

My setup is a bit different than yours, but I was seeing a similar problem. 我的设置与您的设置有些不同,但是我遇到了类似的问题。 I have a setup.cfg file in the root of my python package that looks like this: 我的python包的根目录中有一个setup.cfg文件,看起来像这样:

[nosetests] with-coverage=1 cover-xml=1 cover-xml-file=coverage.xml cover-package=companyname

With this setup.cfg file, I was not seeing companyname/test_base.py show up in the coverage report that nosetests spits out at the end. 有了这个setup.cfg文件,我没有看到鼻子测试最后出现的覆盖率报告中出现了companyname / test_base.py。 I was, however, seeing it show up when I ran coverage report so I know the data is being collected. 但是,我在运行coverage report时看到了它,因此我知道正在收集数据。

My Fix 我的修复

Looking at the documentation I saw a couple of potential options to fix. 在查看文档时,我看到了几个可能要修复的选项。 I was able to resolve the issue by adding cover-tests=1 to my setup.cfg file. 通过将cover-tests=1添加到setup.cfg文件中,我能够解决此问题。 The docs describe this option as 文档将该选项描述为

--cover-tests Include test modules in coverage report

It looks like whatever algorithm nose uses to determine what is a "test" isn't very smart and maybe only looks at class names 看起来任何算法鼻子使用什么来确定什么是“测试”都不是很聪明,并且可能仅查看类名

Your Fix 您的修复

Since you're using the command-line to pass options, I think you need to add --cover-tests when you invoke nosetests 由于您使用命令行来传递选项,因此我认为您在调用鼻子测试时需要添加--cover-tests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM