Dynamically passing variables to unittest

T

Tom Haddon

Hi Folks,

Newbie question here. I'm trying to set up some unit testing for a database abstraction class, and the first thing I want to test is the connection parameters. 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):
"""Check that invalid connect parameters raise InvalidConnectString error"""
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.

Any help appreciated.

Thanks, Tom
 
P

Peter Hansen

Tom said:
> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,147
Latest member
CarenSchni
Top