diff --git a/odoo/addons/base/tests/test_cloc.py b/odoo/addons/base/tests/test_cloc.py index 4c87b3c735d..b6c115e9094 100644 --- a/odoo/addons/base/tests/test_cloc.py +++ b/odoo/addons/base/tests/test_cloc.py @@ -1,6 +1,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -import sys - from odoo.tools import cloc from odoo.tests import TransactionCase, tagged @@ -241,7 +239,7 @@ class TestClocParser(TransactionCase): py_count = cl.parse_py(PY_TEST_NO_RETURN) self.assertEqual(py_count, (2, 2)) py_count = cl.parse_py(PY_TEST) - if sys.version_info >= (3, 8, 0): + if self._python_version >= (3, 8, 0): # Multi line str lineno return the begining of the str # in python 3.8, it result in a different count for # multi str used in expressions diff --git a/odoo/addons/base/tests/test_test_suite.py b/odoo/addons/base/tests/test_test_suite.py index ae8f2e6b814..11af6076c94 100644 --- a/odoo/addons/base/tests/test_test_suite.py +++ b/odoo/addons/base/tests/test_test_suite.py @@ -4,7 +4,6 @@ import difflib import logging import re -import sys from contextlib import contextmanager from unittest import TestCase from unittest.mock import patch @@ -312,7 +311,7 @@ Traceback (most recent call last): self.fail(msg % (login, count, expected, funcname, filename, linenum)) AssertionError: Query count more than expected for user __system__: 1 > 0 in test_assertQueryCount at base/tests/test_test_suite.py:$line ''') - if sys.version_info < (3, 10, 0): + if self._python_version < (3, 10, 0): message = message.replace("with self.assertQueryCount(system=0):", "self.env.cr.execute('SELECT 1')") self.expected_logs = [ diff --git a/odoo/addons/test_lint/tests/test_pylint.py b/odoo/addons/test_lint/tests/test_pylint.py index b41bf6578ae..b436b24e1f6 100644 --- a/odoo/addons/test_lint/tests/test_pylint.py +++ b/odoo/addons/test_lint/tests/test_pylint.py @@ -9,7 +9,6 @@ except ImportError: import subprocess import os from os.path import join -import sys from odoo.tests.common import TransactionCase from odoo import tools @@ -53,7 +52,7 @@ class TestPyLint(TransactionCase): if pylint is None: self._skip_test('please install pylint') required_pylint_version = tools.parse_version('1.6.4') - if sys.version_info >= (3, 6): + if self._python_version >= (3, 6): required_pylint_version = tools.parse_version('1.7.0') if tools.parse_version(getattr(pylint, '__version__', '0.0.1')) < required_pylint_version: self._skip_test('please upgrade pylint to >= %s' % required_pylint_version) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index e16892c552e..ba52c2826a0 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -363,7 +363,9 @@ class BaseCase(unittest.TestCase, metaclass=MetaCase): """ Subclass of TestCase for Odoo-specific code. This class is abstract and expects self.registry, self.cr and self.uid to be initialized by subclasses. """ - if sys.version_info < (3, 8): + + _python_version = sys.version_info + if _python_version < (3, 8): # Partial backport of bpo-24412, merged in CPython 3.8 _class_cleanups = []