From dbaf0cb5addb4b6a5b3655527ad05ac6cd1a531e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= Date: Tue, 4 Jul 2023 08:33:14 +0200 Subject: [PATCH] Adjust tests for taskName attribute added in Python 3.12 gh-91513: Added taskName attribute to logging module for use with asyncio tasks. https://github.com/python/cpython/issues/91513 --- tests/test_jsonlogger.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_jsonlogger.py b/tests/test_jsonlogger.py index af369d2..585998c 100644 --- a/tests/test_jsonlogger.py +++ b/tests/test_jsonlogger.py @@ -41,7 +41,7 @@ def test_default_format(self): def test_percentage_format(self): fr = jsonlogger.JsonFormatter( # All kind of different styles to check the regex - '[%(levelname)8s] %(message)s %(filename)s:%(lineno)d %(asctime)' + '[%(levelname)8s] %(message)s %(filename)s:%(lineno)d %(asctime) %(taskName)' ) self.log_handler.setFormatter(fr) @@ -50,7 +50,7 @@ def test_percentage_format(self): log_json = json.loads(self.buffer.getvalue()) self.assertEqual(log_json["message"], msg) - self.assertEqual(log_json.keys(), {'levelname', 'message', 'filename', 'lineno', 'asctime'}) + self.assertEqual(log_json.keys(), {'levelname', 'message', 'filename', 'lineno', 'asctime', 'taskName'}) def test_rename_base_field(self): fr = jsonlogger.JsonFormatter(rename_fields={'message': '@message'}) @@ -274,7 +274,7 @@ def encode_complex(z): self.log.info(" message", extra=value) msg = self.buffer.getvalue() - self.assertEqual(msg, "{\"message\": \" message\", \"special\": [3.0, 8.0]}\n") + self.assertEqual(msg, "{\"message\": \" message\", \"taskName\": null, \"special\": [3.0, 8.0]}\n") def test_rename_reserved_attrs(self): log_format = lambda x: ['%({0:s})s'.format(i) for i in x] @@ -296,7 +296,7 @@ def test_rename_reserved_attrs(self): self.log.info("message") msg = self.buffer.getvalue() - self.assertEqual(msg, '{"error.type": null, "error.message": null, "log.origin.function": "test_rename_reserved_attrs", "log.level": "INFO", "log.origin.file.name": "test_jsonlogger", "process.name": "MainProcess", "process.thread.name": "MainThread", "log.message": "message"}\n') + self.assertEqual(msg, '{"taskName": null, "error.type": null, "error.message": null, "log.origin.function": "test_rename_reserved_attrs", "log.level": "INFO", "log.origin.file.name": "test_jsonlogger", "process.name": "MainProcess", "process.thread.name": "MainThread", "log.message": "message"}\n') def test_merge_record_extra(self): record = logging.LogRecord("name", level=1, pathname="", lineno=1, msg="Some message", args=None, exc_info=None)