Skip to content

Commit

Permalink
Fix pytest for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgriffin committed Nov 10, 2024
1 parent 98c333a commit ca4789d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"args": [
"-vvv",
"--ignore=coding_tests",
"--ignore=tools",
],
"console": "integratedTerminal",
// "justMyCode": false
Expand Down
16 changes: 10 additions & 6 deletions tests/non_gui/test_mail_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ def test_no_error_logging(caplog: LogCaptureFixture):


def test_exception_logging(caplog: LogCaptureFixture):
with patch("bitcoin_safe.logging_handlers.compose_email") as mock_compose_email:
mock_compose_email.return_value = "Mocked Function"
with patch("bitcoin_safe.logging_handlers.OpenLogHandler.emit") as mock_OpenLogHandler_emit:
mock_OpenLogHandler_emit.return_value = "Mocked OpenLogHandler.emit"
with patch("bitcoin_safe.logging_handlers.compose_email") as mock_compose_email:
mock_compose_email.return_value = "Mocked Function"

with caplog.at_level(logging.INFO):
logger.critical("this should compose an email", exc_info=sys.exc_info())
with caplog.at_level(logging.INFO):
logger.critical("this should compose an email", exc_info=sys.exc_info())

# Assert that the mocked function was called
mock_compose_email.assert_called_once()
# Assert that the mocked function was called
mock_compose_email.assert_called_once()
# Assert that the mocked function was called
mock_OpenLogHandler_emit.assert_called_once()

0 comments on commit ca4789d

Please sign in to comment.