diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-05-14 15:15:50 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-05-14 15:15:50 (GMT) |
commit | e2d66903e8e336817702213f0cd8c3a24edf03ac (patch) | |
tree | dec47334b101cdb50d63548f86c5435193293b6d /Lib/test/test_faulthandler.py | |
parent | e1e04ad8aac819941948b994937f1d42d83a564b (diff) | |
download | cpython-e2d66903e8e336817702213f0cd8c3a24edf03ac.zip cpython-e2d66903e8e336817702213f0cd8c3a24edf03ac.tar.gz cpython-e2d66903e8e336817702213f0cd8c3a24edf03ac.tar.bz2 |
Issue #21497: faulthandler functions now raise a better error if sys.stderr is
None: RuntimeError("sys.stderr is None") instead of AttributeError("'NoneType'
object has no attribute 'fileno'").
Diffstat (limited to 'Lib/test/test_faulthandler.py')
-rw-r--r-- | Lib/test/test_faulthandler.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index ebd99ed..b0fc279 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -591,6 +591,31 @@ sys.exit(exitcode) def test_register_chain(self): self.check_register(chain=True) + @contextmanager + def check_stderr_none(self): + stderr = sys.stderr + try: + sys.stderr = None + with self.assertRaises(RuntimeError) as cm: + yield + self.assertEqual(str(cm.exception), "sys.stderr is None") + finally: + sys.stderr = stderr + + def test_stderr_None(self): + # Issue #21497: provide an helpful error if sys.stderr is None, + # instead of just an attribute error: "None has no attribute fileno". + with self.check_stderr_none(): + faulthandler.enable() + with self.check_stderr_none(): + faulthandler.dump_traceback() + if hasattr(faulthandler, 'dump_traceback_later'): + with self.check_stderr_none(): + faulthandler.dump_traceback_later(1e-3) + if hasattr(faulthandler, "register"): + with self.check_stderr_none(): + faulthandler.register(signal.SIGUSR1) + if __name__ == "__main__": unittest.main() |