https://github.com/python/cpython/commit/2514548b1e6992d16afb3050a958d252457c47e3
commit: 2514548b1e6992d16afb3050a958d252457c47e3
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-14T14:46:49+02:00
summary:
Reuse assert_python_ok() in test_cmd_line (#159377)
support.script_helper no longer strips refcount from -X showrefcount
stderr.
files:
M Lib/test/test_cmd_line.py
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 0af0debd8150e3..82b9d0f86ba421 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -176,35 +176,24 @@ def get_xoptions(*args):
self.assertEqual(opts, {'a': True, 'b': 'c,d=e'})
def test_showrefcount(self):
- def run_python(*args):
- # this is similar to assert_python_ok but doesn't strip
- # the refcount from stderr. It can be replaced once
- # assert_python_ok stops doing that.
- cmd = [sys.executable]
- cmd.extend(args)
- PIPE = subprocess.PIPE
- p = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
- out, err = p.communicate()
- p.stdout.close()
- p.stderr.close()
- rc = p.returncode
- self.assertEqual(rc, 0)
- return rc, out, err
- code = 'import sys; print(sys._xoptions)'
# normally the refcount is hidden
- rc, out, err = run_python('-c', code)
- self.assertEqual(out.rstrip(), b'{}')
- self.assertEqual(err, b'')
+ # (assert_python_ok() enables faulthandler)
+ code = 'import sys; print(sys._xoptions)'
+ proc = assert_python_ok('-c', code)
+ self.assertEqual(proc.out.rstrip(), b"{'faulthandler': True}")
+ self.assertEqual(proc.err, b'')
+
# "-X showrefcount" shows the refcount, but only in debug builds
- rc, out, err = run_python('-I', '-X', 'showrefcount', '-c', code)
- self.assertEqual(out.rstrip(), b"{'showrefcount': True}")
+ proc = assert_python_ok('-I', '-X', 'showrefcount', '-c', code)
+ self.assertEqual(proc.out.rstrip(),
+ b"{'faulthandler': True, 'showrefcount': True}")
if support.Py_DEBUG:
# bpo-46417: Tolerate negative reference count which can occur
# because of bugs in C extensions. This test is only about checking
# the showrefcount feature.
- self.assertRegex(err, br'^\[-?\d+ refs, \d+ blocks\]')
+ self.assertRegex(proc.err, br'^\[-?\d+ refs, \d+ blocks\]')
else:
- self.assertEqual(err, b'')
+ self.assertEqual(proc.err, b'')
@support.cpython_only
def test_xoption_frozen_modules(self):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]