]> granicus.if.org Git - python/commitdiff
Factor out stripping of interpreter debug output in test.support.strip_python_stderr()
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 4 Aug 2010 11:48:56 +0000 (11:48 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 4 Aug 2010 11:48:56 +0000 (11:48 +0000)
Lib/test/support.py
Lib/test/test_subprocess.py
Lib/test/test_threading.py

index 558fbc2a18175155cae3b582a03a02eb1af6c61a..0372f16842708735d59ea9df7ef0451fc4655bdc 100644 (file)
@@ -1243,3 +1243,13 @@ def swap_item(obj, item, new_val):
             yield
         finally:
             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
index e6ba8cb1eac8d9770fdbe3fcdba5926b1483335e..eb0f5d73abef04e43f902eb343a38868dc6d9685 100644 (file)
@@ -53,7 +53,7 @@ class BaseTestCase(unittest.TestCase):
         # In a debug build, stuff like "[6580 refs]" is printed to stderr at
         # shutdown time.  That frustrates tests trying to check stderr produced
         # 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)
 
 
index bf9f90d3b1ba585493f60290c7660a41bf3bde68..39c5a17231becf9794c7b5ed40a4a3da3a6fd369 100644 (file)
@@ -1,7 +1,7 @@
 # Very rudimentary test of threading module
 
 import test.support
-from test.support import verbose
+from test.support import verbose, strip_python_stderr
 import random
 import re
 import sys
@@ -350,7 +350,7 @@ class ThreadTests(BaseTestCase):
         stdout, stderr = p.communicate()
         self.assertEqual(stdout.strip(),
             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"")
 
     def test_enumerate_after_join(self):