bpo-42923: Add Py_FatalError() test in test_capi (GH-24240)
Move faulthandler._fatal_error() to _testcapi.fatal_error().
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index a4ebe4a..0d5c97d 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -547,6 +547,15 @@ def test_pynumber_tobase(self):
self.assertRaises(TypeError, pynumber_tobase, '123', 10)
self.assertRaises(SystemError, pynumber_tobase, 123, 0)
+ def test_fatal_error(self):
+ code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")'
+ with support.SuppressCrashReport():
+ rc, out, err = assert_python_failure('-sSI', '-c', code)
+
+ err = err.replace(b'\r', b'').decode('ascii', 'replace')
+ self.assertIn('Fatal Python error: test_fatal_error: MESSAGE\n',
+ err)
+
class TestPendingCalls(unittest.TestCase):
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 80c1f7d..bc61aab 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -227,25 +227,23 @@ def test_sigill(self):
5,
'Illegal instruction')
+ def check_fatal_error_func(self, release_gil):
+ # Test that Py_FatalError() dumps a traceback
+ with support.SuppressCrashReport():
+ self.check_fatal_error(f"""
+ import _testcapi
+ _testcapi.fatal_error(b'xyz', {release_gil})
+ """,
+ 2,
+ 'xyz',
+ func='test_fatal_error',
+ py_fatal_error=True)
+
def test_fatal_error(self):
- self.check_fatal_error("""
- import faulthandler
- faulthandler._fatal_error(b'xyz')
- """,
- 2,
- 'xyz',
- func='faulthandler_fatal_error_py',
- py_fatal_error=True)
+ self.check_fatal_error_func(False)
def test_fatal_error_without_gil(self):
- self.check_fatal_error("""
- import faulthandler
- faulthandler._fatal_error(b'xyz', True)
- """,
- 2,
- 'xyz',
- func='faulthandler_fatal_error_py',
- py_fatal_error=True)
+ self.check_fatal_error_func(True)
@unittest.skipIf(sys.platform.startswith('openbsd'),
"Issue #12868: sigaltstack() doesn't work on "