[FIX] tests: allow OdooSuite to handle unittest.TestCase without crashing
closes odoo/odoo#79713 X-original-commit: 6ae762f1e4a7f3eb5320d28428310905961dfad3 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -43,6 +43,7 @@ from . import test_res_partner
|
||||
from . import test_res_partner_bank
|
||||
from . import test_res_users
|
||||
from . import test_reports
|
||||
from . import test_test_suite
|
||||
from . import test_tests_tags
|
||||
from . import test_form_create
|
||||
from . import test_cloc
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from odoo.tests import MetaCase
|
||||
|
||||
|
||||
class TestTestSuite(TestCase, metaclass=MetaCase):
|
||||
|
||||
def test_test_suite(self):
|
||||
""" Check that OdooSuite handles unittest.TestCase correctly. """
|
||||
+16
-14
@@ -228,12 +228,13 @@ class OdooSuite(unittest.suite.TestSuite):
|
||||
finally:
|
||||
unittest.suite._call_if_exists(result, '_restoreStdout')
|
||||
if currentClass._classSetupFailed is True:
|
||||
currentClass.doClassCleanups()
|
||||
if len(currentClass.tearDown_exceptions) > 0:
|
||||
for exc in currentClass.tearDown_exceptions:
|
||||
self._createClassOrModuleLevelException(
|
||||
result, exc[1], 'setUpClass', className,
|
||||
info=exc)
|
||||
if hasattr(currentClass, 'doClassCleanups'):
|
||||
currentClass.doClassCleanups()
|
||||
if len(currentClass.tearDown_exceptions) > 0:
|
||||
for exc in currentClass.tearDown_exceptions:
|
||||
self._createClassOrModuleLevelException(
|
||||
result, exc[1], 'setUpClass', className,
|
||||
info=exc)
|
||||
|
||||
def _createClassOrModuleLevelException(self, result, exc, method_name, parent, info=None):
|
||||
errorName = f'{method_name} ({parent})'
|
||||
@@ -276,14 +277,15 @@ class OdooSuite(unittest.suite.TestSuite):
|
||||
className)
|
||||
finally:
|
||||
unittest.suite._call_if_exists(result, '_restoreStdout')
|
||||
previousClass.doClassCleanups()
|
||||
if len(previousClass.tearDown_exceptions) > 0:
|
||||
for exc in previousClass.tearDown_exceptions:
|
||||
className = unittest.util.strclass(previousClass)
|
||||
self._createClassOrModuleLevelException(result, exc[1],
|
||||
'tearDownClass',
|
||||
className,
|
||||
info=exc)
|
||||
if hasattr(previousClass, 'doClassCleanups'):
|
||||
previousClass.doClassCleanups()
|
||||
if len(previousClass.tearDown_exceptions) > 0:
|
||||
for exc in previousClass.tearDown_exceptions:
|
||||
className = unittest.util.strclass(previousClass)
|
||||
self._createClassOrModuleLevelException(result, exc[1],
|
||||
'tearDownClass',
|
||||
className,
|
||||
info=exc)
|
||||
|
||||
|
||||
class MetaCase(type):
|
||||
|
||||
Reference in New Issue
Block a user