Commit 4f050f8a authored by Matias Guijarro's avatar Matias Guijarro
Browse files

tests: make a fixture for excepthook in shell

parent 918d0c37
...@@ -545,27 +545,32 @@ def test_getattribute_evaluation(): ...@@ -545,27 +545,32 @@ def test_getattribute_evaluation():
result, cli, _ = _feed_cli_with_input("a.foo()\r", local_globals={"a": a}) result, cli, _ = _feed_cli_with_input("a.foo()\r", local_globals={"a": a})
def test_excepthook(default_session): @pytest.fixture
print_output = [] def shell_excepthook():
def test_print(*msg, **kw):
print_output.append("\n".join(msg))
orig_excepthook = sys.excepthook orig_excepthook = sys.excepthook
try: try:
install_excepthook() install_excepthook()
logging.getLogger("exceptions").setLevel( yield
1000
) # this is to silent exception logging via logger (which also calls 'print')
with mock.patch("builtins.print", test_print):
try:
raise RuntimeError("excepthook test")
except RuntimeError:
sys.excepthook(*sys.exc_info())
finally: finally:
sys.excepthook = orig_excepthook sys.excepthook = orig_excepthook
def test_excepthook(shell_excepthook, default_session):
print_output = []
def test_print(*msg, **kw):
print_output.append("\n".join(msg))
logging.getLogger("exceptions").setLevel(
1000
) # this is to silent exception logging via logger (which also calls 'print')
with mock.patch("builtins.print", test_print):
try:
raise RuntimeError("excepthook test")
except RuntimeError:
sys.excepthook(*sys.exc_info())
assert ( assert (
"".join(print_output) "".join(print_output)
== "!!! === RuntimeError: excepthook test === !!! ( for more details type cmd 'last_error' )" == "!!! === RuntimeError: excepthook test === !!! ( for more details type cmd 'last_error' )"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment