pombreda / python-nose

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

Patch: use @attr decorator on classes #409

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by jonsibo...@gmail.com on 2 Apr 2011 at 12:48

GoogleCodeExporter commented 9 years ago
Hi, thanks for taking the time to submit a patch.  This actually just got 
implemented a couple weeks ago and will be released in 1.0.1.  It landed in 
revision d0cb12f39682971e8d6504baf3d58a92d0f5e174 for Issue 292

If you get a chance, please try it out the new @attr and report back if you run 
into problems:
pip install hg+https://python-nose.googlecode.com/hg/#egg=Nose

Original comment by kumar.mcmillan on 3 Apr 2011 at 2:35

GoogleCodeExporter commented 9 years ago
It looks pretty good. After 2 years... hah.

Thanks!

Original comment by jonsibo...@gmail.com on 3 Apr 2011 at 4:17