]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-83434: Disable XML in regrtest when -R option is used (#117232)
authorVictor Stinner <vstinner@python.org>
Tue, 26 Mar 2024 07:35:59 +0000 (08:35 +0100)
committerGitHub <noreply@github.com>
Tue, 26 Mar 2024 07:35:59 +0000 (08:35 +0100)
Lib/test/libregrtest/cmdline.py
Lib/test/test_regrtest.py
Misc/NEWS.d/next/Tests/2024-03-25-21-31-49.gh-issue-83434.U7Z8cY.rst [new file with mode: 0644]

index 876b1bcd2ca40668e55e57c2d57687a17246f528..3e7428c4ad37979f378cb75c5a6598e9db613ad2 100644 (file)
@@ -173,6 +173,7 @@ class Namespace(argparse.Namespace):
         self.fail_rerun = False
         self.tempdir = None
         self._add_python_opts = True
+        self.xmlpath = None
 
         super().__init__(**kwargs)
 
@@ -506,17 +507,28 @@ def _parse_args(args, **kwargs):
         ns.randomize = True
     if ns.verbose:
         ns.header = True
+
     # When -jN option is used, a worker process does not use --verbose3
     # and so -R 3:3 -jN --verbose3 just works as expected: there is no false
     # alarm about memory leak.
     if ns.huntrleaks and ns.verbose3 and ns.use_mp is None:
-        ns.verbose3 = False
         # run_single_test() replaces sys.stdout with io.StringIO if verbose3
         # is true. In this case, huntrleaks sees an write into StringIO as
         # a memory leak, whereas it is not (gh-71290).
+        ns.verbose3 = False
         print("WARNING: Disable --verbose3 because it's incompatible with "
               "--huntrleaks without -jN option",
               file=sys.stderr)
+
+    if ns.huntrleaks and ns.xmlpath:
+        # The XML data is written into a file outside runtest_refleak(), so
+        # it looks like a leak but it's not. Simply disable XML output when
+        # hunting for reference leaks (gh-83434).
+        ns.xmlpath = None
+        print("WARNING: Disable --junit-xml because it's incompatible "
+              "with --huntrleaks",
+              file=sys.stderr)
+
     if ns.forever:
         # --forever implies --failfast
         ns.failfast = True
index 903ad50ba088e8634578b4fb0f1afac46258545b..6a6b21102fcae88f613eea997f1e76d8a13f2036 100644 (file)
@@ -464,6 +464,24 @@ class ParseArgsTestCase(unittest.TestCase):
         regrtest = self.create_regrtest(args)
         self.assertTrue(regrtest.want_bisect)
 
+    def test_verbose3_huntrleaks(self):
+        args = ['-R', '3:10', '--verbose3']
+        with support.captured_stderr():
+            regrtest = self.create_regrtest(args)
+        self.assertIsNotNone(regrtest.hunt_refleak)
+        self.assertEqual(regrtest.hunt_refleak.warmups, 3)
+        self.assertEqual(regrtest.hunt_refleak.runs, 10)
+        self.assertFalse(regrtest.output_on_failure)
+
+    def test_xml_huntrleaks(self):
+        args = ['-R', '3:12', '--junit-xml', 'output.xml']
+        with support.captured_stderr():
+            regrtest = self.create_regrtest(args)
+        self.assertIsNotNone(regrtest.hunt_refleak)
+        self.assertEqual(regrtest.hunt_refleak.warmups, 3)
+        self.assertEqual(regrtest.hunt_refleak.runs, 12)
+        self.assertIsNone(regrtest.junit_filename)
+
 
 @dataclasses.dataclass(slots=True)
 class Rerun:
diff --git a/Misc/NEWS.d/next/Tests/2024-03-25-21-31-49.gh-issue-83434.U7Z8cY.rst b/Misc/NEWS.d/next/Tests/2024-03-25-21-31-49.gh-issue-83434.U7Z8cY.rst
new file mode 100644 (file)
index 0000000..7b7a8fc
--- /dev/null
@@ -0,0 +1,3 @@
+Disable JUnit XML output (``--junit-xml=FILE`` command line option) in
+regrtest when hunting for reference leaks (``-R`` option). Patch by Victor
+Stinner.