Skip to content

Commit 2162512

Browse files
[3.12] gh-110367: Make regrtest --verbose3 compatible with --huntrleaks -jN (GH-111577) (#111589)
gh-110367: Make regrtest --verbose3 compatible with --huntrleaks -jN (GH-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. (cherry picked from commit d9a5530) Co-authored-by: Victor Stinner <[email protected]>
1 parent 21c8fbf commit 2162512

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
@@ -494,10 +494,16 @@ def _parse_args(args, **kwargs):
494494
ns.randomize = True
495495
if ns.verbose:
496496
ns.header = True
497-
if ns.huntrleaks and ns.verbose3:
497+
# When -jN option is used, a worker process does not use --verbose3
498+
# and so -R 3:3 -jN --verbose3 just works as expected: there is no false
499+
# alarm about memory leak.
500+
if ns.huntrleaks and ns.verbose3 and ns.use_mp is None:
498501
ns.verbose3 = False
502+
# run_single_test() replaces sys.stdout with io.StringIO if verbose3
503+
# is true. In this case, huntrleaks sees an write into StringIO as
504+
# a memory leak, whereas it is not (gh-71290).
499505
print("WARNING: Disable --verbose3 because it's incompatible with "
500-
"--huntrleaks: see http://bugs.python.org/issue27103",
506+
"--huntrleaks without -jN option",
501507
file=sys.stderr)
502508
if ns.forever:
503509
# --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)