Skip to content

Commit d9a5530

Browse files
authored
gh-110367: Make regrtest --verbose3 compatible with --huntrleaks -jN (#111577)
"./python -m test -j1 -R 3:3 --verbose3" now works as expected, since run_single_test() does not replace sys.stdout with StringIO in this case.
1 parent ef83b3f commit d9a5530

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

Lib/test/libregrtest/cmdline.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,16 @@ def _parse_args(args, **kwargs):
493493
ns.randomize = True
494494
if ns.verbose:
495495
ns.header = True
496-
if ns.huntrleaks and ns.verbose3:
496+
# When -jN option is used, a worker process does not use --verbose3
497+
# and so -R 3:3 -jN --verbose3 just works as expected: there is no false
498+
# alarm about memory leak.
499+
if ns.huntrleaks and ns.verbose3 and ns.use_mp is None:
497500
ns.verbose3 = False
501+
# run_single_test() replaces sys.stdout with io.StringIO if verbose3
502+
# is true. In this case, huntrleaks sees an write into StringIO as
503+
# a memory leak, whereas it is not (gh-71290).
498504
print("WARNING: Disable --verbose3 because it's incompatible with "
499-
"--huntrleaks: see http://bugs.python.org/issue27103",
505+
"--huntrleaks without -jN option",
500506
file=sys.stderr)
501507
if ns.forever:
502508
# --forever implies --failfast

Lib/test/test_regrtest.py

+23
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,29 @@ def test_crash(self):
21202120
self.assertIn(f"Exit code {exitcode} (SIGSEGV)", output)
21212121
self.check_line(output, "just before crash!", full=True, regex=False)
21222122

2123+
def test_verbose3(self):
2124+
code = textwrap.dedent(r"""
2125+
import unittest
2126+
from test import support
2127+
2128+
class VerboseTests(unittest.TestCase):
2129+
def test_pass(self):
2130+
print("SPAM SPAM SPAM")
2131+
""")
2132+
testname = self.create_test(code=code)
2133+
2134+
# Run sequentially
2135+
output = self.run_tests("--verbose3", testname)
2136+
self.check_executed_tests(output, testname, stats=1)
2137+
self.assertNotIn('SPAM SPAM SPAM', output)
2138+
2139+
# -R option needs a debug build
2140+
if support.Py_DEBUG:
2141+
# Check for reference leaks, run in parallel
2142+
output = self.run_tests("-R", "3:3", "-j1", "--verbose3", testname)
2143+
self.check_executed_tests(output, testname, stats=1, parallel=True)
2144+
self.assertNotIn('SPAM SPAM SPAM', output)
2145+
21232146

21242147
class TestUtils(unittest.TestCase):
21252148
def test_format_duration(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make regrtest ``--verbose3`` option compatible with ``--huntrleaks -jN``
2+
options. The ``./python -m test -j1 -R 3:3 --verbose3`` command now works as
3+
expected. Patch by Victor Stinner.

0 commit comments

Comments
 (0)