Skip to content

Tests failing with Python 3.12 (taskName) #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nhairs opened this issue Mar 8, 2024 · 0 comments · Fixed by #2
Closed

Tests failing with Python 3.12 (taskName) #3

nhairs opened this issue Mar 8, 2024 · 0 comments · Fixed by #2
Labels
bug Something isn't working

Comments

@nhairs
Copy link
Owner

nhairs commented Mar 8, 2024

Original Issue: madzak/python-json-logger#185

With Python 3.12 we are seeing the following test cases fail. They don't fail with Python 3.11.

python-json-logger> _______________ TestJsonLogger.test_custom_object_serialization ________________
python-json-logger> 
python-json-logger> self = <tests.test_jsonlogger.TestJsonLogger testMethod=test_custom_object_serialization>
python-json-logger> 
python-json-logger>     def test_custom_object_serialization(self):
python-json-logger>         def encode_complex(z):
python-json-logger>             if isinstance(z, complex):
python-json-logger>                 return (z.real, z.imag)
python-json-logger>             else:
python-json-logger>                 type_name = z.__class__.__name__
python-json-logger>                 raise TypeError("Object of type '{}' is no JSON serializable".format(type_name))
python-json-logger>     
python-json-logger>         formatter = jsonlogger.JsonFormatter(json_default=encode_complex,
python-json-logger>                                              json_encoder=json.JSONEncoder)
python-json-logger>         self.log_handler.setFormatter(formatter)
python-json-logger>     
python-json-logger>         value = {
python-json-logger>             "special": complex(3, 8),
python-json-logger>         }
python-json-logger>     
python-json-logger>         self.log.info(" message", extra=value)
python-json-logger>         msg = self.buffer.getvalue()
python-json-logger> >       self.assertEqual(msg, "{\"message\": \" message\", \"special\": [3.0, 8.0]}\n")
python-json-logger> E       AssertionError: '{"message": " message", "taskName": null, "special": [3.0, 8.0]}\n' != '{"message": " message", "special": [3.0, 8.0]}\n'
python-json-logger> E       - {"message": " message", "taskName": null, "special": [3.0, 8.0]}
python-json-logger> E       ?                        ------------------
python-json-logger> E       + {"message": " message", "special": [3.0, 8.0]}
python-json-logger> 
python-json-logger> tests/test_jsonlogger.py:277: AssertionError
python-json-logger> ------------------------------ Captured log call -------------------------------
python-json-logger> INFO     logging-test-99:test_jsonlogger.py:275  message
python-json-logger> ____________________ TestJsonLogger.test_percentage_format _____________________
python-json-logger> 
python-json-logger> self = <tests.test_jsonlogger.TestJsonLogger testMethod=test_percentage_format>
python-json-logger> 
python-json-logger>     def test_percentage_format(self):
python-json-logger>         fr = jsonlogger.JsonFormatter(
python-json-logger>             # All kind of different styles to check the regex
python-json-logger>             '[%(levelname)8s] %(message)s %(filename)s:%(lineno)d %(asctime)'
python-json-logger>         )
python-json-logger>         self.log_handler.setFormatter(fr)
python-json-logger>     
python-json-logger>         msg = "testing logging format"
python-json-logger>         self.log.info(msg)
python-json-logger>         log_json = json.loads(self.buffer.getvalue())
python-json-logger>     
python-json-logger>         self.assertEqual(log_json["message"], msg)
python-json-logger> >       self.assertEqual(log_json.keys(), {'levelname', 'message', 'filename', 'lineno', 'asctime'})
python-json-logger> E       AssertionError: dict_keys(['levelname', 'message', 'filename', 'lineno', 'asctime', 'taskName']) != {'asctime', 'levelname', 'message', 'filename', 'lineno'}
python-json-logger> 
python-json-logger> tests/test_jsonlogger.py:53: AssertionError
python-json-logger> ------------------------------ Captured log call -------------------------------
python-json-logger> INFO     logging-test-51:test_jsonlogger.py:49 testing logging format
python-json-logger> __________________ TestJsonLogger.test_rename_reserved_attrs ___________________
python-json-logger> 
python-json-logger> self = <tests.test_jsonlogger.TestJsonLogger testMethod=test_rename_reserved_attrs>
python-json-logger> 
python-json-logger>     def test_rename_reserved_attrs(self):
python-json-logger>         log_format = lambda x: ['%({0:s})s'.format(i) for i in x]
python-json-logger>         reserved_attrs_map = {
python-json-logger>             'exc_info': 'error.type',
python-json-logger>             'exc_text': 'error.message',
python-json-logger>             'funcName': 'log.origin.function',
python-json-logger>             'levelname': 'log.level',
python-json-logger>             'module': 'log.origin.file.name',
python-json-logger>             'processName': 'process.name',
python-json-logger>             'threadName': 'process.thread.name',
python-json-logger>             'msg': 'log.message'
python-json-logger>         }
python-json-logger>     
python-json-logger>         custom_format = ' '.join(log_format(reserved_attrs_map.keys()))
python-json-logger>         reserved_attrs = [_ for _ in jsonlogger.RESERVED_ATTRS if _ not in list(reserved_attrs_map.keys())]
python-json-logger>         formatter = jsonlogger.JsonFormatter(custom_format, reserved_attrs=reserved_attrs, rename_fields=reserved_attrs_map)
python-json-logger>         self.log_handler.setFormatter(formatter)
python-json-logger>         self.log.info("message")
python-json-logger>     
python-json-logger>         msg = self.buffer.getvalue()
python-json-logger> >       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')
python-json-logger> E       AssertionError: '{"taskName": null, "error.type": null, "err[227 chars]"}\n' != '{"error.type": null, "error.message": null,[209 chars]"}\n'
python-json-logger> E       - {"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"}
python-json-logger> E       ?  ------------------
python-json-logger> E       + {"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"}
python-json-logger> 
python-json-logger> tests/test_jsonlogger.py:299: AssertionError
python-json-logger> ------------------------------ Captured log call -------------------------------
python-json-logger> INFO     logging-test-68:test_jsonlogger.py:296 message

Per this comment

gh-91513: Added taskName attribute to logging module for use with asyncio tasks. python/cpython#91513

nhairs added a commit that referenced this issue Mar 8, 2024
@nhairs nhairs added the bug Something isn't working label Mar 8, 2024
@nhairs nhairs closed this as completed in #2 Mar 11, 2024
nhairs added a commit that referenced this issue Mar 11, 2024
This updates the supported versions of python including those run in the CI test suite.

- Python versions 3.7-3.13
  - Drops 3.6
- PYPY 3.7-3.10
- Adds MacOS and Windows to test matrix
- Add `taskName` to `RESERVED_ATTRS` (fixes: #3 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant