Add a function to remove html tages from traces

Remove html tags from test case trace test results

Related-prod: PRODX-47162

Change-Id: Ib133ae08ff7422be17996b24f6fb6fa8a540d2d2
diff --git a/update_testrail_xml/cmd.py b/update_testrail_xml/cmd.py
index ea7a5f3..409dbc5 100644
--- a/update_testrail_xml/cmd.py
+++ b/update_testrail_xml/cmd.py
@@ -241,6 +241,7 @@
     reporter.update_testcases(all_empty_cases)
     reporter.delete_duplicates()
     reporter.cut_long_traces(trace_len)
+    reporter.remove_html_tags_in_traces()
     reporter.delete_temporary_file()
 
 
diff --git a/update_testrail_xml/reporter.py b/update_testrail_xml/reporter.py
index 438759c..f0304ab 100644
--- a/update_testrail_xml/reporter.py
+++ b/update_testrail_xml/reporter.py
@@ -257,7 +257,7 @@
             except IndexError:
                 pass
             tree = ET.ElementTree(root)
-            tree.write(self.output_xunit_report)
+            tree.write(self.temporary_filename)
 
     def check_file_exists(self, filename):
         return str(os.path.isfile(filename))
@@ -269,3 +269,25 @@
                 self.check_file_exists(self.temporary_filename)
             )
         )
+
+    def remove_html_tags_in_traces(self):
+        tree = ET.parse(self.temporary_filename)
+        root = tree.getroot()
+
+        if root[0].tag == "testsuite":
+            root = root[0]
+
+        for child in root:
+            try:
+
+                text = child[0].attrib["message"]
+                clean_text = re.sub(r"<(\/?[^>]+)>", r"\1", text)
+                child[0].attrib["message"] = clean_text
+                text = child[0].text
+                clean_text = re.sub(r"<(\/?[^>]+)>", r"\1", text)
+                child[0].text = clean_text
+
+            except (IndexError, KeyError):
+                pass
+            tree = ET.ElementTree(root)
+            tree.write(self.output_xunit_report)