Dynamically passing variables to unittest

Peter Hansen peter at engcorp.com
Wed Dec 15 10:37:20 EST 2004


Tom Haddon wrote:
 > So, my question is, how do I dynamically
 > pass the variables from a list, for example to the unittest module so I
 > can maintain the list of test cases more easily:
 >
 > -------------------------
 > import DB
 > import unittest
 > 

 > class ConnectString(unittest.TestCase): 
 

 >     InvalidStrings=(['pg','test','localhost','5432','test','test']
 >         ,['pg','test','local',5432,'test','test'])
 > 

 >     def testInvalidStrings(self):
 >         for i in InvalidStrings:
 >             self.assertRaises(DB.InvalidConnectString, DB.DB,",".join(i))
 > ------------------------
 >
 > My problem is, this passes one string containing
 > "'pg','test','localhost','5432','test','test'" rather than each
 > one of those as variables.

"As variables"?  What does that mean?  Can you give an
example of precisely what a valid DB.DB call would look
like in the real code, rather than showing an example
of something that *doesn't* do what you want it to?

I thought connect strings looked like "host=localhost;port=5432"
and so on... equal signs and semicolons or something.

-Peter



More information about the Python-list mailing list