Tapan
Tapan

Reputation: 11

Python Nose Annotations

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?

  1. Smoke Test
  2. Load Test
  3. Regression
  4. Long Running Test I want to add label to each individual test cases please provide your suggestions. http://pythontesting.net/framework/nose/nose-introduction/

Upvotes: 0

Views: 851

Answers (3)

Raushendra
Raushendra

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

Kashif Siddiqui
Kashif Siddiqui

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

Amber
Amber

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

Related Questions