mirror of
https://github.com/python/cpython.git
synced 2025-07-17 00:05:20 +00:00
Factor out stripping of interpreter debug output in test.support.strip_python_stderr()
This commit is contained in:
parent
f96482e91a
commit
62f68ed31f
3 changed files with 13 additions and 3 deletions
|
@ -1243,3 +1243,13 @@ def swap_item(obj, item, new_val):
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
del obj[item]
|
del obj[item]
|
||||||
|
|
||||||
|
def strip_python_stderr(stderr):
|
||||||
|
"""Strip the stderr of a Python process from potential debug output
|
||||||
|
emitted by the interpreter.
|
||||||
|
|
||||||
|
This will typically be run on the result of the communicate() method
|
||||||
|
of a subprocess.Popen object.
|
||||||
|
"""
|
||||||
|
stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
|
||||||
|
return stderr
|
||||||
|
|
|
@ -53,7 +53,7 @@ class BaseTestCase(unittest.TestCase):
|
||||||
# In a debug build, stuff like "[6580 refs]" is printed to stderr at
|
# In a debug build, stuff like "[6580 refs]" is printed to stderr at
|
||||||
# shutdown time. That frustrates tests trying to check stderr produced
|
# shutdown time. That frustrates tests trying to check stderr produced
|
||||||
# from a spawned Python process.
|
# from a spawned Python process.
|
||||||
actual = re.sub("\[\d+ refs\]\r?\n?$", "", stderr.decode()).encode()
|
actual = support.strip_python_stderr(stderr)
|
||||||
self.assertEqual(actual, expected, msg)
|
self.assertEqual(actual, expected, msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Very rudimentary test of threading module
|
# Very rudimentary test of threading module
|
||||||
|
|
||||||
import test.support
|
import test.support
|
||||||
from test.support import verbose
|
from test.support import verbose, strip_python_stderr
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -350,7 +350,7 @@ class ThreadTests(BaseTestCase):
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
self.assertEqual(stdout.strip(),
|
self.assertEqual(stdout.strip(),
|
||||||
b"Woke up, sleep function is: <built-in function sleep>")
|
b"Woke up, sleep function is: <built-in function sleep>")
|
||||||
stderr = re.sub(br"^\[\d+ refs\]", b"", stderr, re.MULTILINE).strip()
|
stderr = strip_python_stderr(stderr)
|
||||||
self.assertEqual(stderr, b"")
|
self.assertEqual(stderr, b"")
|
||||||
|
|
||||||
def test_enumerate_after_join(self):
|
def test_enumerate_after_join(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue