Message205864
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. |
|
Date |
User |
Action |
Args |
2013-12-10 22:34:18 | Claudiu.Popa | set | recipients:
+ Claudiu.Popa, michael.foord, docs@python |
2013-12-10 22:34:18 | Claudiu.Popa | set | messageid: <1386714858.72.0.878231586551.issue19950@psf.upfronthosting.co.za> |
2013-12-10 22:34:18 | Claudiu.Popa | link | issue19950 messages |
2013-12-10 22:34:18 | Claudiu.Popa | create | |
|