Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Nose plugin intended to provide ordered test execution.
"""
In some cases during testing you will want test execution to occur in a certain order. For example while performaing some forms of integration testing. This plugin is intended to provide this type of ordered test execution by decorating the tests with a step number.
def Foo(unittest.TestCase):
@step(number=1)
def test_foo(self):
pass
@step(number=2)
def test_boo(self):
pass
"""
import logging
import os
from nose import loader
from nose.plugins import Plugin
log = logging.getLogger('nose.plugins.step')
def step(**kwargs):
"""
Define ordered steps
"""
def wrapped(obj):
for key, value in kwargs.iteritems():
setattr(obj, key, value)
return obj
return wrapped
class Steps(Plugin):
"""
Order the tests within a unittest.TestCase defined by the @step decorator
"""
name = 'steps'
def options(self, parser, env=os.environ):
"""
Register commandline options.
"""
Plugin.options(self, parser, env)
parser.add_option('--steps', action='store_true', dest='steps',
help="Order the tests within a unittest.TestCase class")
def configure(self, options, conf):
"""
Configure plugin.
"""
Plugin.configure(self, options, conf)
if options.steps:
self.enabled = True
def loadTestsFromTestCase(self, cls):
"""
Return tests in this test case class. Ordered by the step definitions.
"""
l = loader.TestLoader()
tmp = l.loadTestsFromTestCase(cls)
test_order = []
for test in tmp._tests:
order = test.test._testMethodName
func = getattr(cls, test.test._testMethodName)
if hasattr(func, 'number'):
order = getattr(func, 'number')
test_order.append((test, order))
test_order.sort(key=lambda tup: tup[1])
tmp._tests = (t[0] for t in test_order)
return tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.