[TIP] Using one unit test with different input parameters

Robert McHardy robert at mchardy.net
Tue Feb 19 10:18:14 PST 2008


Hi there,

I'm using twill and selenium to test a client's websites.  I've got  
unit tests set up for different pages etc, checking for things such  
as failed include messages, and this is working fine with a hard- 
coded domain in my test script.  This example will happily test the  
wessexfm.com domain...

--------- tw_test.py -----------

import unittest, time, re
from twill import get_browser
from twill.commands import find, notfind, title, code

DOMAIN = {'primary': 'wessexfm.com', 'code': 'wx',}

class Site_Test(unittest.TestCase):
     def setUp(self):
         self.tb = get_browser()
     def test_homepage(self):
         """Test the / homepage"""
         self.tb.go('http://www.%s/' % DOMAIN['primary'])
         code(200)
         notfind('error occurred while processing this directive')

	... etc ...

if __name__ == "__main__":
     unittest.main()

-----------------------------------------

The client has 28 sites that are very similar.  I'd rather not have  
to clone the test script 28 times with different hard-coded domain  
details...  but I can't figure out how to pass in different  
parameters to the unit test - e.g. a different DOMAIN dict with data  
for other sites, and have the tests run on that domain instead.

Any tips or hints gratefully received!

Cheers, Rob.

-- 
Robert McHardy - London, UK



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/testing-in-python/attachments/20080219/9a7d616b/attachment.htm 


More information about the testing-in-python mailing list