-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
minimal example:
import logging
from unittest import mock
class Boom:
def __str__(self) -> str:
raise ValueError('nope!')
@mock.patch.object(logging, "raiseExceptions", False)
def test_does_not_error():
logging.error(Boom())passes without:
$ pytest -qq t.py
. [100%]fails with:
$ pytest -qq t.py --json-report --json-report-file out.json
F [100%]
=================================== FAILURES ===================================
_____________________________ test_does_not_error ______________________________
@mock.patch.object(logging, "raiseExceptions", False)
def test_does_not_error():
> logging.error(Boom())
t.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:2190: in error
root.error(msg, *args, **kwargs)
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:1568: in error
self._log(ERROR, msg, args, **kwargs)
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:1684: in _log
self.handle(record)
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:1700: in handle
self.callHandlers(record)
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:1762: in callHandlers
hdlr.handle(record)
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:1028: in handle
self.emit(record)
venv/lib/python3.12/site-packages/pytest_jsonreport/plugin.py:319: in emit
d['msg'] = record.getMessage()
/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py:390: in getMessage
msg = str(self.msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <t.Boom object at 0x10558b110>
def __str__(self) -> str:
> raise ValueError('nope!')
E ValueError: nope!
t.py:6: ValueError
=========================== short test summary info ============================
FAILED t.py::test_does_not_error - ValueError: nope!
it would seem that pytest-json-report's logging handler needs something similar to the stdlib's:
a workaround appears to be to disable the log component:
$ pytest -qq t.py --json-report --json-report-file out.json --json-report-omit log
. [100%]Metadata
Metadata
Assignees
Labels
No labels