Dynamically passing variables to unittest

Tom Haddon thaddon at equilar.com
Wed Dec 15 12:37:10 EST 2004


Hi Peter,

Yeah, you're right, the term "ConnectString" is a little confusing. Perhaps I should change that.

Here's a valid call to DB:

conn=DB.DB('pg','test','localhost',5432,'test','test')

In the context of this unittest, a valid syntax would be (except that this unittest would fail, as this is a "good" connection:

self.assertRaises(DB.InvalidConnectString, DB.DB,'pg','test','localhost',5432,'test','test')

Thanks, Tom

-----Original Message-----
From: Peter Hansen [mailto:peter at engcorp.com]
Sent: Wednesday, December 15, 2004 7:37 AM
To: python-list at python.org
Subject: Re: Dynamically passing variables to unittest


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