unit testing, setUp and scoping
john maclean
jayeola at gmail.com
Wed Apr 14 11:51:17 EDT 2010
On 14 April 2010 16:22, Francisco Souza <francisco at franciscosouza.net> wrote:
>> On Wed, Apr 14, 2010 at 11:47 AM, john maclean <jayeola at gmail.com> wrote:
>> 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
>
> Hi John,
> each TestCase is a object, and you can "store" attributes in this objects
> normally, using self :)
>
> class TestPythonStringsTestCase(
>>
>> unittest.TestCase):
>> def setUp(self):
>> print '''setting up stuff for ''', __name__
>> self.s1 = 'single string'
>> print dir(str)
>>
>> def testclass(self):
>> '''test strings are of class str'''
>> self.assertEqual(self.s1.__class__, str)
>>
>> if __name__ == "__main__":
>> unittest.main()
>
> This works fine and s1 is an internal attribute of your TesteCase.
>
> Best regards,
> Francisco Souza
> Software developer at Giran and also full time
> Open source evangelist at full time
>
> http://www.franciscosouza.net
> Twitter: @franciscosouza
> (27) 8128 0652
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
Thanks! that worked.
--
John Maclean
07739 171 531
MSc (DIC)
Enterprise Linux Systems Engineer
More information about the Python-list
mailing list