Skip to content

Commit adf28d5

Browse files
committed
[FIX] tests: allow OdooSuite to handle unittest.TestCase without crashing
closes odoo#79669 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
1 parent ffca224 commit adf28d5

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

odoo/addons/base/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@
3636
from . import test_res_partner_bank
3737
from . import test_res_users
3838
from . import test_reports
39+
from . import test_test_suite
3940
from . import test_tests_tags
4041
from . import test_cloc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
4+
from unittest import TestCase
5+
6+
7+
class TestTestSuite(TestCase):
8+
test_tags = {'standard', 'at_install'}
9+
test_module = 'base'
10+
11+
def test_test_suite(self):
12+
""" Check that OdooSuite handles unittest.TestCase correctly. """

odoo/tests/common.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,13 @@ def _handleClassSetUp(self, test, result):
200200
finally:
201201
unittest.suite._call_if_exists(result, '_restoreStdout')
202202
if currentClass._classSetupFailed is True:
203-
currentClass.doClassCleanups()
204-
if len(currentClass.tearDown_exceptions) > 0:
205-
for exc in currentClass.tearDown_exceptions:
206-
self._createClassOrModuleLevelException(
207-
result, exc[1], 'setUpClass', className,
208-
info=exc)
203+
if hasattr(currentClass, 'doClassCleanups'):
204+
currentClass.doClassCleanups()
205+
if len(currentClass.tearDown_exceptions) > 0:
206+
for exc in currentClass.tearDown_exceptions:
207+
self._createClassOrModuleLevelException(
208+
result, exc[1], 'setUpClass', className,
209+
info=exc)
209210

210211
def _createClassOrModuleLevelException(self, result, exc, method_name, parent, info=None):
211212
errorName = '%s (%s)' % (method_name, parent)
@@ -248,14 +249,15 @@ def _tearDownPreviousClass(self, test, result):
248249
className)
249250
finally:
250251
unittest.suite._call_if_exists(result, '_restoreStdout')
251-
previousClass.doClassCleanups()
252-
if len(previousClass.tearDown_exceptions) > 0:
253-
for exc in previousClass.tearDown_exceptions:
254-
className = unittest.util.strclass(previousClass)
255-
self._createClassOrModuleLevelException(result, exc[1],
256-
'tearDownClass',
257-
className,
258-
info=exc)
252+
if hasattr(previousClass, 'doClassCleanups'):
253+
previousClass.doClassCleanups()
254+
if len(previousClass.tearDown_exceptions) > 0:
255+
for exc in previousClass.tearDown_exceptions:
256+
className = unittest.util.strclass(previousClass)
257+
self._createClassOrModuleLevelException(result, exc[1],
258+
'tearDownClass',
259+
className,
260+
info=exc)
259261

260262

261263
class TreeCase(unittest.TestCase):

0 commit comments

Comments
 (0)