How to generate multiple function calls with dict.items() in the PyUnit framework?
So, I am trying to create a unittest.TestCase that creates several different databases with different member types and verifies something about the data(not important for this context). I wanted to use a generator to pass the necessary information from a global dict to the function which will take care of the object creation and verification.
Currently, it will only setUp, run, and tearDown the first variant of the test. How can I generate several distinct (i.e. varying parameters from a data structure such as a dict) calls to my method, which has to determine how to populate the database based on the member type? Each call should be run as a separate test and have the setUp and tearDown performed every time. The test case is being run with PyUnit in the Pydev GUI.
import sys, os, socket, shutil, unittest
# Global counter for test generation
testRun = 1
# test dictionary for generating multiple tests
basicMembers = {"Int" : 1}
# test operations to generate federations
def addItemAndGetSizeOf(basicMember, expectedValue, testFileName):
print "foo %s %s %s" % (basicMember, expectedValue, testFileName)
class BasicMembers(unittest.TestCase):
t开发者_高级运维estFileName = "bar" + str(testRun)
def setUp(self):
global testRun
testRun += 1
print testRun
def tearDown(self):
pass
def testBasicMembers(self):
for basicMember, expectedValue in basicMembers.items():
yield addItemAndGetSizeOf, basicMember, expectedValue, self.testFileName
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
精彩评论