Reputation: 11
I want to label each individual test case with annotations @SmokeTest
or @LoadTest
@RegressionTest
or @LongRunningTest
.
Will it be possible to categorize each test case into one of the following categories, using Python nose that provide annotations?
Upvotes: 0
Views: 851
Reputation: 1
Add attributes using @attr
to label test cases, and classes as well, with annotations:
from nose.plugins.attrib import attr
@attr(priority='first')
def test_support_1():
#test details...
@attr(priority='second')
def test_support_2():
#test details...
Run it as:
nosetests -a priority=first
nosetests -a priority=second
In Python 2.6 and higher, @attr
can be set on classes as below:
@attr(priority='sanity')
class MyTestCase:
def test_support_1(self):
pass
def test_support_2(self):
pass
Run it as:
nosetests -a priority=sanity
Upvotes: 0
Reputation: 1546
Add attributes using @attr
. @attr
can be set for classes as well the same way as below if you want to run the whole class
Refer: http://nose.readthedocs.org/en/latest/plugins/attrib.html
from nose.plugins.attrib import attr
@attr('smoke')
def test_awesome_1():
# your test...
@attr('load')
def test_awesome_2():
# your test...
@attr('regression')
def test_awesome_3():
# your test...
@attr('regression')
def test_awesome_4():
# your test...
and then run it as
nosetests -a 'smoke' #Runs test_awesome_1 only
nosetests -a 'load' #Runs test_awesome_2 only
nosetests -a 'regression' #Runs test_awesome_3 and test_awesome_4
Upvotes: 2
Reputation: 526473
It's hard to tell exactly what you're asking, but it sounds like you might be looking for the built-in nose
plugin 'Attrib' which lets you set attributes for tests (and select groups of tests based on attributes).
Upvotes: 1