changeset 45407:de9ec12ee53c

run-tests: refactor filtering logic for --retest flag How I got to this: While re-running failed tests using --retest I noticed that the output: "running x tests using y parallel processes". was not actually correct, because x was the total number of tests present in the directory, but it should be the number of failed tests. Although it would run only the failed tests and later will say that remaining tests were skipped. Changes in test files reflect the fixed behaviour. This patch change and move the logic for filtering failed test for --retest option and make sure that we create instances of class Test only for the tests we need to run. As mentioned in the deleted text (in this patch itself) the logic for --retest should be outside of TestSuite. Differential Revision: https://phab.mercurial-scm.org/D8938
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Sat, 22 Aug 2020 16:31:34 +0530
parents fa1a5527f642
children 543e446204c6
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Thu Aug 27 12:24:57 2020 +0530
+++ b/tests/run-tests.py	Sat Aug 22 16:31:34 2020 +0530
@@ -2336,7 +2336,6 @@
         jobs=1,
         whitelist=None,
         blacklist=None,
-        retest=False,
         keywords=None,
         loop=False,
         runs_per_test=1,
@@ -2364,9 +2363,6 @@
         backwards compatible behavior which reports skipped tests as part
         of the results.
 
-        retest denotes whether to retest failed tests. This arguably belongs
-        outside of TestSuite.
-
         keywords denotes key words that will be used to filter which tests
         to execute. This arguably belongs outside of TestSuite.
 
@@ -2377,7 +2373,6 @@
         self._jobs = jobs
         self._whitelist = whitelist
         self._blacklist = blacklist
-        self._retest = retest
         self._keywords = keywords
         self._loop = loop
         self._runs_per_test = runs_per_test
@@ -2407,10 +2402,6 @@
                     result.addSkip(test, 'blacklisted')
                     continue
 
-                if self._retest and not os.path.exists(test.errpath):
-                    result.addIgnore(test, 'not retesting')
-                    continue
-
                 if self._keywords:
                     with open(test.path, 'rb') as f:
                         t = f.read().lower() + test.bname.lower()
@@ -3253,6 +3244,22 @@
                     tests.append({'path': t})
             else:
                 tests.append({'path': t})
+
+        if self.options.retest:
+            retest_args = []
+            for test in tests:
+                if 'case' in test:
+                    # for multiple dimensions test cases
+                    casestr = b'#'.join(test['case'])
+                    errpath = b'%s#%s.err' % (test['path'], casestr)
+                else:
+                    errpath = b'%s.err' % test['path']
+                if self.options.outputdir:
+                    errpath = os.path.join(self.options.outputdir, errpath)
+
+                if os.path.exists(errpath):
+                    retest_args.append(test)
+            tests = retest_args
         return tests
 
     def _runtests(self, testdescs):
@@ -3298,7 +3305,6 @@
                 jobs=jobs,
                 whitelist=self.options.whitelisted,
                 blacklist=self.options.blacklist,
-                retest=self.options.retest,
                 keywords=kws,
                 loop=self.options.loop,
                 runs_per_test=self.options.runs_per_test,
--- a/tests/test-run-tests.t	Thu Aug 27 12:24:57 2020 +0530
+++ b/tests/test-run-tests.t	Sat Aug 22 16:31:34 2020 +0530
@@ -497,7 +497,7 @@
 ====================
 
   $ rt --retest
-  running 2 tests using 1 parallel processes 
+  running 1 tests using 1 parallel processes 
   
   --- $TESTTMP/test-failure.t
   +++ $TESTTMP/test-failure.t.err
@@ -512,7 +512,7 @@
   ERROR: test-failure.t output changed
   !
   Failed test-failure.t: output changed
-  # Ran 2 tests, 1 skipped, 1 failed.
+  # Ran 1 tests, 0 skipped, 1 failed.
   python hash seed: * (glob)
   [1]
 
@@ -521,7 +521,7 @@
   $ mkdir output
   $ mv test-failure.t.err output
   $ rt --retest --outputdir output
-  running 2 tests using 1 parallel processes 
+  running 1 tests using 1 parallel processes 
   
   --- $TESTTMP/test-failure.t
   +++ $TESTTMP/output/test-failure.t.err
@@ -536,7 +536,7 @@
   ERROR: test-failure.t output changed
   !
   Failed test-failure.t: output changed
-  # Ran 2 tests, 1 skipped, 1 failed.
+  # Ran 1 tests, 0 skipped, 1 failed.
   python hash seed: * (glob)
   [1]
 
@@ -975,7 +975,7 @@
   [1]
 
   $ rt --retest
-  running 5 tests using 1 parallel processes 
+  running 1 tests using 1 parallel processes 
   
   --- $TESTTMP/test-cases.t
   +++ $TESTTMP/test-cases.t#b#c.err
@@ -990,7 +990,7 @@
   ERROR: test-cases.t#b#c output changed
   !
   Failed test-cases.t#b#c: output changed
-  # Ran 5 tests, 4 skipped, 1 failed.
+  # Ran 1 tests, 0 skipped, 1 failed.
   python hash seed: * (glob)
   [1]
   $ rm test-cases.t#b#c.err