unit testing, setUp and scoping

J

john maclean

Can one use the setUp block to store variables so that they can be
used elsewhere in unit tests? I'm thinking that it's better to have
variables created in another script and have it imported from within
the unit test

#!/usr/bin/env python
'''create knowledge base of strings by unit testing'''
import unittest

class TestPythonStringsTestCase(unittest.TestCase):
def setUp(self):
print '''setting up stuff for ''', __name__
s1 = 'single string'
print dir(str)

def testclass(self):
'''test strings are of class str'''
self.assertEqual(s1.__class__, str)

if __name__ == "__main__":
unittest.main()



--
John Maclean
07739 171 531
MSc (DIC)

Enterprise Linux Systems Engineer
 
B

Bruno Desthuilliers

john maclean a écrit :
Can one use the setUp block to store variables so that they can be
used elsewhere in unit tests? I'm thinking that it's better to have
variables created in another script and have it imported from within
the unit test
???


#!/usr/bin/env python
'''create knowledge base of strings by unit testing'''
import unittest

class TestPythonStringsTestCase(unittest.TestCase):
def setUp(self):
print '''setting up stuff for ''', __name__
s1 = 'single string'
print dir(str)

def testclass(self):
'''test strings are of class str'''
self.assertEqual(s1.__class__, str)


Err... What about FIRST doing the FineTutorial ???

class TestPythonStringsTestCase(unittest.TestCase):
def setUp(self):
self.s1 = 'single string'

def testclass(self):
"test strings are of class str"
self.assert(type(self.s1) is str)
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top