diff --git a/avocado/plugins/xunit.py b/avocado/plugins/xunit.py index d865f297b503ba32425b27bfc375b2cdc7d2131a..b34ad7d48acf234e4207b6f677aead7e804f84af 100644 --- a/avocado/plugins/xunit.py +++ b/avocado/plugins/xunit.py @@ -38,7 +38,13 @@ class XmlResult(object): return quoteattr(attrib) def _escape_cdata(self, cdata): - return cdata.replace(']]>', ']]>]]>', ']]>]]>', ']]>]]> %s: %s", self.status, self.tagged_name, - self.fail_reason.__class__.__name__, + self.fail_class, self.fail_reason) else: diff --git a/examples/tests/failtest_nasty.py b/examples/tests/failtest_nasty.py new file mode 100755 index 0000000000000000000000000000000000000000..b9ca90873bd7b723360e93fcde4c526faebcd15f --- /dev/null +++ b/examples/tests/failtest_nasty.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +from avocado import test +from avocado import job + + +class NastyException(Exception): + + """ Please never use something like this!!! """ + + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return self.msg + + +class FailTest(test.Test): + + """ + Very nasty exception test + """ + + def action(self): + """ + Should fail not-that-badly + """ + raise NastyException("Nasty-string-like-exception") + + +if __name__ == "__main__": + job.main() diff --git a/examples/tests/failtest_nasty2.py b/examples/tests/failtest_nasty2.py new file mode 100755 index 0000000000000000000000000000000000000000..71dac05b04a983362694df839183ffd3a2271031 --- /dev/null +++ b/examples/tests/failtest_nasty2.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +from avocado import test +from avocado import job + + +class NastyException(Exception): + + """ Please never use something like this!!! """ + + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return self.msg + + +class FailTest(test.Test): + + """ + Very nasty exception test + """ + + def action(self): + """ + Should fail. + """ + raise NastyException(None) # str(Exception) fails! + + +if __name__ == "__main__": + job.main() diff --git a/selftests/all/functional/avocado/standalone_tests.py b/selftests/all/functional/avocado/standalone_tests.py index 5b9b915373d4d00e61411000ec05f03afad8a928..3d7b620f9720b4658ae3b7f1dcfc80d3b899670b 100644 --- a/selftests/all/functional/avocado/standalone_tests.py +++ b/selftests/all/functional/avocado/standalone_tests.py @@ -26,6 +26,7 @@ class StandaloneTests(unittest.TestCase): self.assertEqual(result.exit_status, expected_rc, "Stand alone %s did not return rc " "%d:\n%s" % (tstname, expected_rc, result)) + return result def test_passtest(self): cmd_line = './examples/tests/passtest.py' @@ -47,6 +48,23 @@ class StandaloneTests(unittest.TestCase): expected_rc = 1 self.run_and_check(cmd_line, expected_rc, 'failtest') + def test_failtest_nasty(self): + cmd_line = './examples/tests/failtest_nasty.py' + expected_rc = 1 + result = self.run_and_check(cmd_line, expected_rc, 'failtest_nasty') + exc = "NastyException: Nasty-string-like-exception" + count = result.stderr.count("\n%s" % exc) + self.assertEqual(count, 2, "Exception \\n%s should be present twice in" + "the log (once from the log, second time when parsing" + "exception details." % (exc)) + + def test_failtest_nasty2(self): + cmd_line = './examples/tests/failtest_nasty2.py' + expected_rc = 1 + result = self.run_and_check(cmd_line, expected_rc, 'failtest_nasty2') + self.assertIn("Exception: Unable to get exception, check the traceback" + " for details.", result.stderr) + def test_errortest(self): cmd_line = './examples/tests/errortest.py' expected_rc = 1