[PATCH 2 of 2] run-tests: add information about skipped tests to XUnit output

Siddharth Agarwal sid0 at fb.com
Wed Jun 7 18:47:18 EDT 2017


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1496875626 25200
#      Wed Jun 07 15:47:06 2017 -0700
# Node ID 8e05986478080f8eefd5f645166020d7802175e8
# Parent  0bdfd2f0e15b0d4a20ea4d288e0b4e04f37f25b4
run-tests: add information about skipped tests to XUnit output

The XUnit spec supports skipped tests.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -2061,6 +2061,17 @@ class TextTestRunner(unittest.TextTestRu
             failelem.appendChild(cd)
             t.appendChild(failelem)
             s.appendChild(t)
+        for tc, message in result.skipped:
+            # According to the schema, 'skipped' has no attributes. So store
+            # the skip message as a text node instead.
+            t = doc.createElement('testcase')
+            t.setAttribute('name', tc.name)
+            message = cdatasafe(message).decode('utf-8', 'replace')
+            cd = doc.createCDATASection(message)
+            skipelem = doc.createElement('skipped')
+            skipelem.appendChild(cd)
+            t.appendChild(skipelem)
+            s.appendChild(t)
         outf.write(doc.toprettyxml(indent='  ', encoding='utf-8'))
 
     @staticmethod
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -676,6 +676,10 @@ Skips with xml
   <?xml version="1.0" encoding="utf-8"?>
   <testsuite errors="0" failures="0" name="run-tests" skipped="2" tests="2">
     <testcase name="test-success.t" time="*"/> (glob)
+    <testcase name="test-skip.t">
+      <skipped>
+  <![CDATA[missing feature: nail clipper]]>    </skipped>
+    </testcase>
   </testsuite>
 
 Missing skips or blacklisted skips don't count as executed:


More information about the Mercurial-devel mailing list