nose-devs/nose — Issue #105: attrib plugin not handling queries spanning class and method attributes
Author: jpellerin
Created: 2011-12-14 15:59:28+00:00
State: closed

What steps will reproduce the problem?

def test_wantClass__comparison(self):
""" Demonstrate that nose's built-in attrib.py plugin can't
handle a query that spans method and class attributes. """

class MyTestClass1(unittest.TestCase):
def test_method1(self):
pass
test_method1.api = 'search'
MyTestClass1.kind = 'api'

selector = AttributeSelector()
selector.attribs = [[('kind','api'),('api','search')]]
wanted = selector.wantClass(MyTestClass1)
self.assertEqual(wanted, True) # fails!

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

I expect the above test to pass. It does not.

What version of the product are you using? On what operating system?

Nose 0.11.1 on CentOS 5 64-bit and python2.6.

Please provide any additional information below.

The problem seems to be that attrib.py's wantClass() is calling
wantFunction() instead of wantMethod() so that the method's class is not
inspected for attributes. I believe the following changes to wantClass()
and wantMethod() will fix this issue:

def wantClass(self, cls):
"""Accept the class if the class is derived from unittest.TestCase
or has the word 'test' in it.
"""
cls_attr = cls.__dict__
if self.validateAttrib(cls_attr) is not False:
return None
# Methods in __dict__.values() are functions, oddly enough.
methods = filter(isfunction, cls_attr.values())
for method in methods:
if self.wantMethod(method, cls) is not False:
return None
return False

def wantMethod(self, method, cls=None):
if cls is None:
cls = method.im_class
attribs = AttributeGetter(cls, method)
return self.validateAttrib(attribs)

Google Code Info:
Issue #: 324
Author: rob.dayl...@gmail.com
Created On: 2010-03-05T19:46:11.000Z
Closed On: 2011-05-02T20:34:49.000Z