This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Claudiu.Popa
Recipients Claudiu.Popa, docs@python, michael.foord
Date 2013-12-10.22:34:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386714858.72.0.878231586551.issue19950@psf.upfronthosting.co.za>
In-reply-to
Content
I was surprised that in the following __init__ is actually called once per test function, although nothing in documentation implied so.

a.py
------

import unittest

class A(unittest.TestCase):
   def __init__(self, *args, **kwargs):
       print('called only once!')
       super().__init__(*args, **kwargs)

   def test(self):
       self.assertEqual(1, 1)
 
   def test2(self):
       self.assertEqual(2, 2)

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

$ python a.py
called only once!
called only once!
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK



The attached patch adds a note regarding this behaviour for the TestCase class.
History
Date User Action Args
2013-12-10 22:34:18Claudiu.Popasetrecipients: + Claudiu.Popa, michael.foord, docs@python
2013-12-10 22:34:18Claudiu.Popasetmessageid: <1386714858.72.0.878231586551.issue19950@psf.upfronthosting.co.za>
2013-12-10 22:34:18Claudiu.Popalinkissue19950 messages
2013-12-10 22:34:18Claudiu.Popacreate