nose-devs/nose — Issue #415: Patch: use @attr decorator on classes
Author: jpellerin
Created: 2011-12-14 16:10:47+00:00
State: open

Instead of:

class Tests(object):

def test_big_download():
pass
Tests.slow = 1

I'd like to be able to have an uniform way of decorating both classes and functions/methods:

@attr(slow=1)
class Tests(object):

def test_big_download():
pass

--- lib/python2.6/site-packages/nose/plugins/attrib.py.orig 2011-04-01 17:42:10.000000000 -0700
+++ lib/python2.6/site-packages/nose/plugins/attrib.py 2011-04-01 17:42:27.000000000 -0700
@@ -90,7 +90,7 @@
import logging
import os
import sys
-from inspect import isfunction
+from inspect import isfunction, isclass
from nose.plugins.base import Plugin
from nose.util import tolist

@@ -105,7 +105,11 @@
for name in args:
# these are just True flags:
setattr(func, name, 1)
- func.__dict__.update(kwargs)
+ if isclass(func):
+ for k,v in kwargs.items():
+ setattr(func, k, v)
+ else:
+ func.__dict__.update(kwargs)
return func
return wrap

Google Code Info:
Issue #: 409
Author: jonsibo...@gmail.com
Created On: 2011-04-02T00:48:33.000Z
Closed On: 2011-04-03T02:35:53.000Z