[issue19950] Document that unittest.TestCase.__init__ is called once per test
Claudiu.Popa
report at bugs.python.org
Tue Dec 10 23:34:18 CET 2013
New submission from Claudiu.Popa:
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.
----------
assignee: docs at python
components: Documentation
files: unittest_init.patch
keywords: patch
messages: 205864
nosy: Claudiu.Popa, docs at python, michael.foord
priority: normal
severity: normal
status: open
title: Document that unittest.TestCase.__init__ is called once per test
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file33086/unittest_init.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19950>
_______________________________________
More information about the Python-bugs-list
mailing list