##// END OF EJS Templates
run-tests: factor out xunit write code into another method...
Siddharth Agarwal -
r32700:3afe258f default
parent child Browse files
Show More
@@ -1932,33 +1932,8 b' class TextTestRunner(unittest.TextTestRu'
1932 self.stream.writeln('Errored %s: %s' % (test.name, msg))
1932 self.stream.writeln('Errored %s: %s' % (test.name, msg))
1933
1933
1934 if self._runner.options.xunit:
1934 if self._runner.options.xunit:
1935 with open(self._runner.options.xunit, 'wb') as xuf:
1935 with open(self._runner.options.xunit, "wb") as xuf:
1936 timesd = dict((t[0], t[3]) for t in result.times)
1936 self._writexunit(result, xuf)
1937 doc = minidom.Document()
1938 s = doc.createElement('testsuite')
1939 s.setAttribute('name', 'run-tests')
1940 s.setAttribute('tests', str(result.testsRun))
1941 s.setAttribute('errors', "0") # TODO
1942 s.setAttribute('failures', str(failed))
1943 s.setAttribute('skipped', str(skipped + ignored))
1944 doc.appendChild(s)
1945 for tc in result.successes:
1946 t = doc.createElement('testcase')
1947 t.setAttribute('name', tc.name)
1948 t.setAttribute('time', '%.3f' % timesd[tc.name])
1949 s.appendChild(t)
1950 for tc, err in sorted(result.faildata.items()):
1951 t = doc.createElement('testcase')
1952 t.setAttribute('name', tc)
1953 t.setAttribute('time', '%.3f' % timesd[tc])
1954 # createCDATASection expects a unicode or it will
1955 # convert using default conversion rules, which will
1956 # fail if string isn't ASCII.
1957 err = cdatasafe(err).decode('utf-8', 'replace')
1958 cd = doc.createCDATASection(err)
1959 t.appendChild(cd)
1960 s.appendChild(t)
1961 xuf.write(doc.toprettyxml(indent=' ', encoding='utf-8'))
1962
1937
1963 if self._runner.options.json:
1938 if self._runner.options.json:
1964 jsonpath = os.path.join(self._runner._testdir, b'report.json')
1939 jsonpath = os.path.join(self._runner._testdir, b'report.json')
@@ -2055,6 +2030,36 b' class TextTestRunner(unittest.TextTestRu'
2055 cuser, csys, real, start, end = tdata[1:6]
2030 cuser, csys, real, start, end = tdata[1:6]
2056 self.stream.writeln(cols % (start, end, cuser, csys, real, test))
2031 self.stream.writeln(cols % (start, end, cuser, csys, real, test))
2057
2032
2033 @staticmethod
2034 def _writexunit(result, outf):
2035 timesd = dict((t[0], t[3]) for t in result.times)
2036 doc = minidom.Document()
2037 s = doc.createElement('testsuite')
2038 s.setAttribute('name', 'run-tests')
2039 s.setAttribute('tests', str(result.testsRun))
2040 s.setAttribute('errors', "0") # TODO
2041 s.setAttribute('failures', str(len(result.failures)))
2042 s.setAttribute('skipped', str(len(result.skipped) +
2043 len(result.ignored)))
2044 doc.appendChild(s)
2045 for tc in result.successes:
2046 t = doc.createElement('testcase')
2047 t.setAttribute('name', tc.name)
2048 t.setAttribute('time', '%.3f' % timesd[tc.name])
2049 s.appendChild(t)
2050 for tc, err in sorted(result.faildata.items()):
2051 t = doc.createElement('testcase')
2052 t.setAttribute('name', tc)
2053 t.setAttribute('time', '%.3f' % timesd[tc])
2054 # createCDATASection expects a unicode or it will
2055 # convert using default conversion rules, which will
2056 # fail if string isn't ASCII.
2057 err = cdatasafe(err).decode('utf-8', 'replace')
2058 cd = doc.createCDATASection(err)
2059 t.appendChild(cd)
2060 s.appendChild(t)
2061 outf.write(doc.toprettyxml(indent=' ', encoding='utf-8'))
2062
2058 class TestRunner(object):
2063 class TestRunner(object):
2059 """Holds context for executing tests.
2064 """Holds context for executing tests.
2060
2065
General Comments 0
You need to be logged in to leave comments. Login now