import subprocess
import sys
from test import support, script_helper
+from test.script_helper import assert_python_ok
import tempfile
import unittest
finally:
sys.stderr = orig_stderr
+ def test_disabled_by_default(self):
+ # By default, the module should be disabled
+ code = "import faulthandler; print(faulthandler.is_enabled())"
+ rc, stdout, stderr = assert_python_ok("-c", code)
+ stdout = (stdout + stderr).strip()
+ self.assertEqual(stdout, b"False")
+
+ def test_sys_xoptions(self):
+ # Test python -X faulthandler
+ code = "import faulthandler; print(faulthandler.is_enabled())"
+ rc, stdout, stderr = assert_python_ok("-X", "faulthandler", "-c", code)
+ stdout = (stdout + stderr).strip()
+ self.assertEqual(stdout, b"True")
+
def check_dump_traceback(self, filename):
"""
Explicitly call dump_traceback() function and check its output.
_PyImportHooks_Init();
- /* initialize the faulthandler module */
- if (_PyFaulthandler_Init())
- Py_FatalError("Py_Initialize: can't initialize faulthandler");
-
/* Initialize _warnings. */
_PyWarnings_Init();
import_init(interp, sysmod);
+ /* initialize the faulthandler module */
+ if (_PyFaulthandler_Init())
+ Py_FatalError("Py_Initialize: can't initialize faulthandler");
+
_PyTime_Init();
if (initfsencoding(interp) < 0)