diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-07-10 14:40:33 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-07-10 14:48:24 +0200 |
commit | e206d346ced90aa4d8d8411baa1f9cc92406f16c (patch) | |
tree | ef3a75d2a4653ec4662abc5be63c8bdbae659306 | |
parent | 75945e68cfeeebb69f29dbfc7013a9de970160d2 (diff) | |
download | qutebrowser-e206d346ced90aa4d8d8411baa1f9cc92406f16c.tar.gz qutebrowser-e206d346ced90aa4d8d8411baa1f9cc92406f16c.zip |
log: Set line number to -1 if it's None for Qt messages
If lineno is set to None in the LogRecord, pytest's logging formatting fails:
tests/unit/utils/test_log.py:418: in test_empty_message
log.qt_message_handler(QtCore.QtDebugMsg, self.Context(), "")
qutebrowser/utils/log.py:508: in qt_message_handler
qt.handle(record)
/usr/lib/python3.8/logging/__init__.py:1587: in handle
self.callHandlers(record)
/usr/lib/python3.8/logging/__init__.py:1649: in callHandlers
hdlr.handle(record)
/usr/lib/python3.8/logging/__init__.py:950: in handle
self.emit(record)
../../pytest/src/_pytest/logging.py:326: in emit
super().emit(record)
/usr/lib/python3.8/logging/__init__.py:1089: in emit
self.handleError(record)
/usr/lib/python3.8/logging/__init__.py:1081: in emit
msg = self.format(record)
/usr/lib/python3.8/logging/__init__.py:925: in format
return fmt.format(record)
../../pytest/src/_pytest/logging.py:89: in format
return super().format(record)
/usr/lib/python3.8/logging/__init__.py:667: in format
s = self.formatMessage(record)
/usr/lib/python3.8/logging/__init__.py:636: in formatMessage
return self._style.format(record)
../../pytest/src/_pytest/logging.py:185: in format
return self._fmt % record.__dict__
E TypeError: %d format: a number is required, not NoneType
According to typeshed, lineno should never be None:
https://github.com/python/typeshed/blob/028f0d52931fe1f96bb25d066186961159c1f801/stdlib/2and3/logging/__init__.pyi#L386
Thus, this is our fault, not pytest's. However, before pytest 6.0.0, pytest did
not surface logging errors:
https://github.com/pytest-dev/pytest/pull/7231
https://github.com/pytest-dev/pytest/commit/b13fcb23d79b3f38e497824c438c926a0a015561
Thus, we never noticed something was going wrong here.
-rw-r--r-- | qutebrowser/utils/log.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 197f594f9..f82ba290e 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -477,6 +477,11 @@ def qt_message_handler(msg_type: QtCore.QtMsgType, else: level = qt_to_logging[msg_type] + if context.line is None: + lineno = -1 + else: + lineno = context.line + if context.function is None: func = 'none' # type: ignore[unreachable] elif ':' in context.function: @@ -503,7 +508,7 @@ def qt_message_handler(msg_type: QtCore.QtMsgType, else: stack = None - record = qt.makeRecord(name, level, context.file, context.line, msg, (), + record = qt.makeRecord(name, level, context.file, lineno, msg, (), None, func, sinfo=stack) qt.handle(record) |