[IMP] tests: make python version accessible without importing sys

closes odoo/odoo#108202

X-original-commit: 27575ed59476238c76d40143d81f6975f1934f7c
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
Xavier-Do
2022-12-16 19:37:53 +01:00
parent e583a1f8f4
commit f842ae07d2
4 changed files with 6 additions and 8 deletions
+1 -3
View File
@@ -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
+1 -2
View File
@@ -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 = [
+1 -2
View File
@@ -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)
+3 -1
View File
@@ -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 = []