[Baypiggies] Question about unittest, setUp and suites
Herbert Pfennig
herbert at albinen.com
Mon May 4 20:29:26 CEST 2009
Hi All,
Long time lurker with a simple question about unittest. I have googled around
and have not really found a good answer to the following question. How do I
define a _setUp_ that only get's called before a suite of tests is run?
(_not_ for every test)
Unittest talks about running a test fixture for a test or a number of
tests but I cannot seem to get this to work for me...
The best solution I could come up with was to do something like this:
import unittest
ran_suite_setup = False
class TestSuite(unittest.TestCase):
def setUp(self):
global ran_suite_setup
if ran_suite_setup is False:
print "Running Suite Setup"
ran_suite_setup = True
print 'Doing some test setup'
def test_001(self):
print 'Hi, I am test1'
def test_002(self):
print 'Hi, I am test2'
if __name__ == '__main__':
unittest.main()
I am not crazy about using globals :) Is this right, or is there a better way
to do this? Any ideas are very appreciated.
~hp
More information about the Baypiggies
mailing list