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

tests: make a fixture for excepthook in shell

parent 918d0c37
......@@ -545,15 +545,22 @@ def test_getattribute_evaluation():
result, cli, _ = _feed_cli_with_input("a.foo()\r", local_globals={"a": a})
def test_excepthook(default_session):
@pytest.fixture
def shell_excepthook():
orig_excepthook = sys.excepthook
try:
install_excepthook()
yield
finally:
sys.excepthook = orig_excepthook
def test_excepthook(shell_excepthook, default_session):
print_output = []
def test_print(*msg, **kw):
print_output.append("\n".join(msg))
orig_excepthook = sys.excepthook
try:
install_excepthook()
logging.getLogger("exceptions").setLevel(
1000
) # this is to silent exception logging via logger (which also calls 'print')
......@@ -563,8 +570,6 @@ def test_excepthook(default_session):
raise RuntimeError("excepthook test")
except RuntimeError:
sys.excepthook(*sys.exc_info())
finally:
sys.excepthook = orig_excepthook
assert (
"".join(print_output)
......
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