From: Christian Herdtweck Date: Fri, 24 Nov 2023 14:46:46 +0000 (+0100) Subject: Adapt unittests for different tracebacks on python 3.11 X-Git-Tag: v1.7.3~1^2~3 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4a5abe5302ed8e6e693ddf8729d3ca778200b685;p=pyi2ncommon Adapt unittests for different tracebacks on python 3.11 Apparently, error tracebacks now have extra lines with pointers to the position in the line where the error occurred. Exact version, where this happens, is unknown. --- diff --git a/test/test_log_helpers.py b/test/test_log_helpers.py index 46ad2cd..0423e0a 100644 --- a/test/test_log_helpers.py +++ b/test/test_log_helpers.py @@ -12,6 +12,7 @@ from tempfile import mkstemp import os from os.path import isfile, basename import re +import sys from src import log_helpers @@ -46,11 +47,15 @@ class LogHelperTest(unittest.TestCase): enumerate(zip(log_reader, expected_contents.splitlines())): if re.match(r'\d{1,2}:\d{2}:\d{2}:\d{3}\s+', actual_line): cmp_line = actual_line[13:].rstrip() - elif re.match(r'\s*File ".+", line \d+, in .+', actual_line): + elif re.match(r'\s*File ".+", line \d+, in .+', actual_line) \ + or re.match(r'\s+~\^~\s*', actual_line): cmp_line = ' TRACEBACK LINE REPLACED' else: cmp_line = actual_line.rstrip() - self.assertEqual(cmp_line, expect_line) + self.assertEqual(cmp_line, expect_line, + msg="Unexpected line in output (line {line_no+1}:\n" \ + "expect: {expect_line}\n" \ + " got: {cmp_line}") def test_short_level_format(self): """Tests that calls to :py:class:`ShortLevelFormatter` do not fail.""" @@ -104,7 +109,10 @@ class LogHelperTest(unittest.TestCase): 'err | 1/0 still does not work! [regular levelname=ERROR]\n' \ 'Traceback (most recent call last):\n' \ ' TRACEBACK LINE REPLACED\n' \ - ' impossible_result = 1/0\n' \ + ' impossible_result = 1/0\n' + if sys.version_info[0] > 3 or sys.version_info[0] == 3 and sys.version_info[1] > 7: + expected_contents += ' TRACEBACK LINE REPLACED\n' + expected_contents += \ 'ZeroDivisionError: division by zero\n' \ 'info| done testing [regular levelname=INFO]\n' self.check_expected_contents(expected_contents)