Add tests for aitbc-core package (Python 3.13 fix) #18

Merged
oib merged 1 commits from aitbc1/7-add-tests-for-aitbc-core-package into main 2026-03-15 20:53:06 +01:00
2 changed files with 8 additions and 2 deletions

View File

@@ -33,7 +33,12 @@ class StructuredLogFormatter(logging.Formatter):
# Add exception info if present
if record.exc_info:
payload["exception"] = self.formatException(record.exc_info)
ei = record.exc_info
# In Python 3.12+, exc_info can be True to indicate lazy capture; resolve it now.
if ei is True:
ei = sys.exc_info()
if ei:
payload["exception"] = self.formatException(ei)
# Add stack info if present
if record.stack_info:

View File

@@ -64,6 +64,7 @@ class TestStructuredLogFormatter:
try:
1 / 0
except ZeroDivisionError:
import sys
record = logging.LogRecord(
name="error.logger",
level=logging.ERROR,
@@ -71,7 +72,7 @@ class TestStructuredLogFormatter:
lineno=30,
msg="Error occurred",
args=(),
exc_info=True, # capture current exception
exc_info=sys.exc_info(),
)
output = formatter.format(record)
data = json.loads(output)