bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

cover-package string matching is too naive #433

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Have an module called "cal" and a python environment where the standard lib 
'calendar' module is imported

2. I'm using django_nose with these commands:

./manage.py test --with-coverage --cover-package="cal,ros" -s

What is the expected output? What do you see instead?

I'd expect it only run coverage for the module called "cal" and not a module 
such as "calendar". 
Also, there is no module called "ros". I'd expect nose to ignore that or 
perhaps raise an error even. Here's the output I get:

Name                     Stmts   Miss  Cover   Missing
------------------------------------------------------
cal                          0      0   100%   
cal.context_processors      12      0   100%   
cal.models                   0      0   100%   
cal.urls                     3      0   100%   
cal.views                   63      1    98%   71
calendar                   381    381     0%   8-708
roster                       0      0   100%   
roster.api                  79      8    90%   24, 43-44, 73-79
roster.forms                55      1    98%   33
roster.models               28      1    96%   17
roster.urls                  3      0   100%   
roster.views               301     42    86%   119-141, 143-151, 187, 195, 201, 
207, 394, 460-475
------------------------------------------------------
TOTAL                      925    434    53%   

I'd expect not to see "calendar" in there and I didn't type "roster" either.  

What version of the product are you using? On what operating system?
1.0.0 on osx. 

Please provide any additional information below.

The code that is too naive is this:

        if self.coverPackages:
            for package in self.coverPackages:
                if (name.startswith(package)
                    and (self.coverTests
                         or not self.conf.testMatch.search(name))):
                    log.debug("coverage for %s", name)
                    return True

That's inslude plugins/nose.py

This piece of code solves the problem:

        import re
        if self.coverPackages:
            for package in self.coverPackages:
                if (re.findall(r'^%s\b' % re.escape(package), name)
                    and (self.coverTests
                         or not self.conf.testMatch.search(name))):
                    log.debug("coverage for %s", name)
                    return True

Original issue reported on code.google.com by pete...@gmail.com on 8 Jul 2011 at 11:06

GoogleCodeExporter commented 8 years ago
Thanks Peter!  I pushed your change to revision 
98f0073f640a771be2b34c7b60370320f0f62f0e And you can grab it by pip install'ing 
Nose from the Mercurial source.

If you'd like to help prevent this from happening again, it would be great if 
you could add a test.  You can see DEVELOPERS.txt in the source for details on 
how to set up Nose's suite.

Original comment by kumar.mcmillan on 8 Jul 2011 at 3:54