Dynamically passing variables to unittest
Jim Sizelove
sizelji at insightbb.com
Wed Dec 15 14:27:55 EST 2004
Tom Haddon wrote:
> 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')
>
You can try something like this (not tested):
>>> InvalidStrings=(['pg','test','localhost','5432','test','test'],
['pg','test','local',5432,'test','test'])
>>> for S in InvalidStrings:
... self.assertRaises(DB.InvalidConnectString, DB.DB, *S)
...
Here the * operator unpacks a sequence when passed in to a function that
is expecting positional arguments. See the Python Tutorial, 4.7.4
Unpacking Argument Lists for a better explanation.
http://docs.python.org/tut/node6.html
hth,
Jim
More information about the Python-list
mailing list