Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62f68ed

Browse files
committed
Factor out stripping of interpreter debug output in test.support.strip_python_stderr()
1 parent f96482e commit 62f68ed

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/support.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,3 +1243,13 @@ def swap_item(obj, item, new_val):
12431243
yield
12441244
finally:
12451245
del obj[item]
1246+
1247+
def strip_python_stderr(stderr):
1248+
"""Strip the stderr of a Python process from potential debug output
1249+
emitted by the interpreter.
1250+
1251+
This will typically be run on the result of the communicate() method
1252+
of a subprocess.Popen object.
1253+
"""
1254+
stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
1255+
return stderr

Lib/test/test_subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def assertStderrEqual(self, stderr, expected, msg=None):
5353
# In a debug build, stuff like "[6580 refs]" is printed to stderr at
5454
# shutdown time. That frustrates tests trying to check stderr produced
5555
# from a spawned Python process.
56-
actual = re.sub("\[\d+ refs\]\r?\n?$", "", stderr.decode()).encode()
56+
actual = support.strip_python_stderr(stderr)
5757
self.assertEqual(actual, expected, msg)
5858

5959

Lib/test/test_threading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Very rudimentary test of threading module
22

33
import test.support
4-
from test.support import verbose
4+
from test.support import verbose, strip_python_stderr
55
import random
66
import re
77
import sys
@@ -350,7 +350,7 @@ def child():
350350
stdout, stderr = p.communicate()
351351
self.assertEqual(stdout.strip(),
352352
b"Woke up, sleep function is: <built-in function sleep>")
353-
stderr = re.sub(br"^\[\d+ refs\]", b"", stderr, re.MULTILINE).strip()
353+
stderr = strip_python_stderr(stderr)
354354
self.assertEqual(stderr, b"")
355355

356356
def test_enumerate_after_join(self):

0 commit comments

Comments
 (0)