About Me

My photo
I Love Bugs! Yum! Yum!

Wednesday, January 19, 2011

Python decorators to group tests

Thursday, February 18, 2010

The foll. code runs only the tests which has "regression" in the annotation.

decoratortest.py:
---------------

#!/usr/bin/env python
import unittest
import time

class decotest(unittest.TestCase):
def Tests(value):
def decorator(target):
target.attribute = value
if target.attribute.find('regression') != -1 :
print target.__name__ + ":" + target.attribute
return target
return decorator

@Tests('regression, acceptance')
def test_abc(self):
print "What's passed:" + self.test_abc.attribute
print "I'm test_abc"

@Tests('smoke, acceptance')
def test_cde(self):
print "I'm test_cde"

calldecotest.py:
-------------------

#!/usr/bin/env python

import unittest
from decoratortest import decotest

def main():
suite = unittest.TestSuite()
test_support.run_unittest(decotest)

if __name__ == "__main__":
main()

No comments:

Post a Comment