Attribute selector plugin.
Oftentimes when testing you will want to select tests based on criteria rather then simply by filename. For example, you might want to run all tests except for the slow ones. You can do this with the Attribute selector plugin by setting attributes on your test methods. Here is an example:
def test_big_download():
import urllib
# commence slowness...
test_big_download.slow = 1
Once you’ve assigned an attribute slow = 1 you can exclude that test and all other tests having the slow attribute by running
$ nosetests -a '!slow'
There is also a decorator available for you that will set attributes. Here’s how to set slow=1 like above with the decorator:
from nose.plugins.attrib import attr
@attr('slow')
def test_big_download():
import urllib
# commence slowness...
And here’s how to set an attribute with a specific value:
from nose.plugins.attrib import attr
@attr(speed='slow')
def test_big_download():
import urllib
# commence slowness...
This test could be run with
$ nosetests -a speed=slow
Below is a reference to the different syntaxes available.
Examples of using the -a and --attr options:
Only runs tests with attribute “status” having value “stable”
Runs tests having both attributes and values
Runs tests that match either attribute
If a test’s tags attribute was a list and it contained the value http then it would be run
Runs tests with the attribute slow if its value does not equal False (False, [], “”, etc...)
Runs tests that do NOT have the attribute slow or have a slow attribute that is equal to False NOTE: if your shell (like bash) interprets ‘!’ as a special character make sure to put single quotes around it.
Examples using the -A and --eval-attr options:
Run only tests that have attributes specified by ATTR [NOSE_ATTR]
Run only tests for whose attributes the Python expression EXPR evaluates to True [NOSE_EVAL_ATTR]
Bases: nose.plugins.base.Plugin
Selects test cases to be run based on their attributes.
Configure the plugin and system, based on selected options.
attr and eval_attr may each be lists.
self.attribs will be a list of lists of tuples. In that list, each list is a group of attributes, all of which must match for the rule to match.
Register command line options
Accept the class if the class or any method is wanted.
Accept the function if its attributes match.
Accept the method if its attributes match.