nose-devs/nose — Issue #430: cover-package string matching is too naive
Author: jpellerin
Created: 2011-12-14 16:11:14+00:00
State: closed

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

Google Code Info:
Issue #: 433
Author: pete...@gmail.com
Created On: 2011-07-08T11:06:22.000Z
Closed On: 2011-07-08T15:54:51.000Z