Skip to content

Commit 2514548

Browse files
authored
Reuse assert_python_ok() in test_cmd_line (#159377)
support.script_helper no longer strips refcount from -X showrefcount stderr.
1 parent 8ff41c2 commit 2514548

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

‎Lib/test/test_cmd_line.py‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,24 @@ def get_xoptions(*args):
176176
self.assertEqual(opts, {'a': True, 'b': 'c,d=e'})
177177

178178
def test_showrefcount(self):
179-
def run_python(*args):
180-
# this is similar to assert_python_ok but doesn't strip
181-
# the refcount from stderr. It can be replaced once
182-
# assert_python_ok stops doing that.
183-
cmd = [sys.executable]
184-
cmd.extend(args)
185-
PIPE = subprocess.PIPE
186-
p = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
187-
out, err = p.communicate()
188-
p.stdout.close()
189-
p.stderr.close()
190-
rc = p.returncode
191-
self.assertEqual(rc, 0)
192-
return rc, out, err
193-
code = 'import sys; print(sys._xoptions)'
194179
# normally the refcount is hidden
195-
rc, out, err = run_python('-c', code)
196-
self.assertEqual(out.rstrip(), b'{}')
197-
self.assertEqual(err, b'')
180+
# (assert_python_ok() enables faulthandler)
181+
code = 'import sys; print(sys._xoptions)'
182+
proc = assert_python_ok('-c', code)
183+
self.assertEqual(proc.out.rstrip(), b"{'faulthandler': True}")
184+
self.assertEqual(proc.err, b'')
185+
198186
# "-X showrefcount" shows the refcount, but only in debug builds
199-
rc, out, err = run_python('-I', '-X', 'showrefcount', '-c', code)
200-
self.assertEqual(out.rstrip(), b"{'showrefcount': True}")
187+
proc = assert_python_ok('-I', '-X', 'showrefcount', '-c', code)
188+
self.assertEqual(proc.out.rstrip(),
189+
b"{'faulthandler': True, 'showrefcount': True}")
201190
if support.Py_DEBUG:
202191
# bpo-46417: Tolerate negative reference count which can occur
203192
# because of bugs in C extensions. This test is only about checking
204193
# the showrefcount feature.
205-
self.assertRegex(err, br'^\[-?\d+ refs, \d+ blocks\]')
194+
self.assertRegex(proc.err, br'^\[-?\d+ refs, \d+ blocks\]')
206195
else:
207-
self.assertEqual(err, b'')
196+
self.assertEqual(proc.err, b'')
208197

209198
@support.cpython_only
210199
def test_xoption_frozen_modules(self):

0 commit comments

Comments
 (0)