Test exceptions handler.
This commit is contained in:
parent
09b7a25f9d
commit
c13e329208
1 changed files with 43 additions and 0 deletions
43
tests/pricehist/test_exceptions.py
Normal file
43
tests/pricehist/test_exceptions.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import logging
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pricehist import exceptions
|
||||
|
||||
|
||||
def test_handler_logs_debug_information(caplog):
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
try:
|
||||
with exceptions.handler():
|
||||
raise exceptions.RequestError("Some message")
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
assert caplog.records[0].levelname == "DEBUG"
|
||||
assert "exception encountered" in caplog.records[0].message
|
||||
assert caplog.records[0].exc_info
|
||||
|
||||
|
||||
def test_handler_exits_nonzero(caplog):
|
||||
with pytest.raises(SystemExit) as e:
|
||||
with exceptions.handler():
|
||||
raise exceptions.RequestError("Some message")
|
||||
|
||||
assert e.value.code == 1
|
||||
|
||||
|
||||
def test_handler_logs_critical_information(caplog):
|
||||
with caplog.at_level(logging.CRITICAL):
|
||||
try:
|
||||
with exceptions.handler():
|
||||
raise exceptions.RequestError("Some message")
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
assert any(
|
||||
[
|
||||
"CRITICAL" == r.levelname and "Some message" in r.message
|
||||
for r in caplog.records
|
||||
]
|
||||
)
|
Loading…
Add table
Reference in a new issue