"""
Examples of test function/method attribute usage with patched nose
Simple syntax (-a, --attr) examples:
* nosetests -a status=stable
=> only test cases with attribute "status" having value "stable"
* nosetests -a priority=2,status=stable
=> both attributes must match
* nosetests -a tags=http
=> attribute list "tags" must contain value "http" (see test_foobar() below for definition)
* nosetests -a slow
=> attribute "slow" must be defined and its value cannot equal to False (False, [], "", etc...)
* nosetests -a !slow
=> attribute "slow" must NOT be defined or its value must be equal to False
Eval expression syntax (-A, --eval-attr) examples:
* nosetests -A "not slow"
* nosetests -A "(priority > 5) and not slow"
This example and the accompanied patch is in public domain, free for any use.
email: mika.eloranta@gmail.com
"""
def attr(**kwargs):
"""Add attributes to a test function/method/class"""
def wrap(func):
func.__dict__.update(kwargs)
return func
return wrap
@attr(priority = 1)
def test_dummy():
print "dummy"
@attr(status = "stable", slow = True, priority = 1, tags = ["http", "pop", "imap"]) def test_foobar():
print "foobar"
def test_fluffy():
print "fluffy"
test_fluffy.status = "unstable"
test_fluffy.slow = True
test_fluffy.priority = 2
class TestSomething:
@attr(status = "stable", priority = 2)
def test_xyz(self):
print "xyz"
class TestOverride:
value = "class"
@attr(value = "method")
def test_override(self):
print "override"
def test_inherit(self):
print "inherit"