diff --git a/avocado/plugins/xunit.py b/avocado/plugins/xunit.py index e1a583073f5aa627bd7304c886000e6fc325df4b..ada40e58613101507e839ec27eac9981cc340c9c 100644 --- a/avocado/plugins/xunit.py +++ b/avocado/plugins/xunit.py @@ -71,12 +71,12 @@ class XUnitResult(Result): if log_size < max_log_size: text_output = logfile_obj.read() else: - size = max_log_size / 2 + size = int(max_log_size / 2) logfile_obj.seek(0, 0) text_output = logfile_obj.read(size) text_output += ("\n\n--[ CUT DUE TO XML PER TEST " "LIMIT ]--\n\n") - logfile_obj.seek(-size / 2, 2) + logfile_obj.seek(log_size - size, 0) text_output += logfile_obj.read() else: text_output = logfile_obj.read() diff --git a/selftests/unit/test_xunit.py b/selftests/unit/test_xunit.py index 14a578046bfe24bcce9e9e86d00c2b4aafc2c1e8..a2ad17fa172c12556f7446415069a212d065fbf5 100644 --- a/selftests/unit/test_xunit.py +++ b/selftests/unit/test_xunit.py @@ -97,6 +97,7 @@ class xUnitSucceedTest(unittest.TestCase): def test_max_test_log_size(self): log = tempfile.NamedTemporaryFile(dir=self.tmpdir, delete=False) log_content = b"1234567890" * 100 + log_content += b"this should not be present" + b"0987654321" * 100 log.write(log_content) log_path = log.name log.close() @@ -117,6 +118,14 @@ class xUnitSucceedTest(unittest.TestCase): "Length of xunit limitted to 10 chars was greater " "than (unlimited - 500). Unlimited output:\n%s\n\n" "Limited output:\n%s" % (unlimited, limited)) + self.assertIn(b"this should not be present", unlimited) + self.assertNotIn(b"this should not be present", limited) + self.assertIn(b"1234567890", unlimited) + self.assertNotIn(b"1234567890", limited) + self.assertIn(b"12345", limited) + self.assertIn(b"0987654321", unlimited) + self.assertNotIn(b"0987654321", limited) + self.assertIn(b"54321", limited) if __name__ == '__main__':