Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 993176e

Browse files
committed
Capture output of CallbackRegistry exception test.
If running `pytest -s`, the default exception handler will print out the traceback, appearing as if there were an error. But this is exactly what this test is checking, so capture output and check it.
1 parent 8511771 commit 993176e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/matplotlib/tests/test_cbook.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,23 @@ def test_pickling(self):
226226
"callbacks")
227227

228228

229-
def test_callbackregistry_default_exception_handler(monkeypatch):
229+
def test_callbackregistry_default_exception_handler(capsys, monkeypatch):
230230
cb = cbook.CallbackRegistry()
231231
cb.connect("foo", lambda: None)
232+
232233
monkeypatch.setattr(
233234
cbook, "_get_running_interactive_framework", lambda: None)
234235
with pytest.raises(TypeError):
235236
cb.process("foo", "argument mismatch")
237+
outerr = capsys.readouterr()
238+
assert outerr.out == outerr.err == ""
239+
236240
monkeypatch.setattr(
237241
cbook, "_get_running_interactive_framework", lambda: "not-none")
238242
cb.process("foo", "argument mismatch") # No error in that case.
243+
outerr = capsys.readouterr()
244+
assert outerr.out == ""
245+
assert "takes 0 positional arguments but 1 was given" in outerr.err
239246

240247

241248
def raising_cb_reg(func):

0 commit comments

Comments
 (0)