Skip to content

Commit

Permalink
Fix tests for the custom Python environment
Browse files Browse the repository at this point in the history
This commit is the cherry-picked commit
f8d36d4

[FIX] tests/common: Fix tests on Windows and with Debian release

closes odoo#119895

Signed-off-by: Xavier Dollé (xdo) <[email protected]>
  • Loading branch information
johnw-bluemark authored and borna-ng committed Oct 15, 2024
1 parent 589b7e3 commit 751b883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions odoo/addons/base/tests/test_test_suite.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import contextlib
import difflib
import logging
import re
from contextlib import contextmanager
from pathlib import PurePath
from unittest import TestCase
from unittest.mock import patch

Expand Down Expand Up @@ -124,12 +126,14 @@ def _log_error(self, message):
self.test_result.addError(self, (AssertionError, AssertionError(message), None))

def _clean_message(self, message):
root_path = __file__.replace('/odoo/addons/base/tests/test_test_suite.py', '')
root_path = PurePath(__file__).parents[4] # removes /odoo/addons/base/tests/test_test_suite.py
python_path = PurePath(contextlib.__file__).parent # /usr/lib/pythonx.x, C:\\python\\Lib, ...
message = re.sub(r'line \d+', 'line $line', message)
message = re.sub(r'py:\d+', 'py:$line', message)
message = re.sub(r'decorator-gen-\d+', 'decorator-gen-xxx', message)
message = re.sub(r'python[\d\.]+', 'python', message)
message = message.replace(f'{root_path}', '/root_path/odoo')
message = message.replace(f'"{root_path}', '"/root_path/odoo')
message = message.replace(f'"{python_path}', '"/usr/lib/python')
message = message.replace('\\', '/')
return message


Expand Down
3 changes: 2 additions & 1 deletion odoo/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ def assertQueryCount(self, default=0, flush=True, **counters):
if count != expected:
# add some info on caller to allow semi-automatic update of query count
frame, filename, linenum, funcname, lines, index = inspect.stack()[2]
filename = filename.replace('\\', '/')
if "/odoo/addons/" in filename:
filename = filename.rsplit("/odoo/addons/", 1)[1]
if count > expected:
Expand Down Expand Up @@ -676,7 +677,7 @@ def _complete_traceback(self, initial_tb):
# method since the error does not comme especially from the test method.
while tb:
code = tb.tb_frame.f_code
if code.co_filename.endswith('/unittest/case.py') and code.co_name in ('_callTestMethod', '_callSetUp', '_callTearDown', '_callCleanup'):
if pathlib.PurePath(code.co_filename).name == 'case.py' and code.co_name in ('_callTestMethod', '_callSetUp', '_callTearDown', '_callCleanup'):
return tb.tb_next
tb = tb.tb_next

Expand Down

0 comments on commit 751b883

Please sign in to comment.