"""
import io
-from pathlib import Path
from paramiko import ChannelFile
if self.unittest_xml:
error_msg = None
try:
- error_msg = find_unittest_error(self.unittest_xml)
+ error_msg = find_unittest_error(self.unittest_xml, self.client)
except Exception as exc:
self.logger.error('Unable to scan logs, exception occurred: {exc}'.format(exc=repr(exc)))
if error_msg:
name=self.hostname,
)
-def find_unittest_error(xmlfile_path):
+def find_unittest_error(xmlfile_path, client):
"""
Load the unit test output XML file
and parse for failures and errors.
if not xmlfile_path:
return "No XML file was passed to process!"
try:
- xml_path = Path(xmlfile_path)
- if xml_path.is_file():
- tree = etree.parse(xmlfile_path)
+ (_, stdout, _) = client.exec_command(f'cat {xmlfile_path}', timeout=200)
+ if stdout:
+ tree = etree.parse(stdout)
failed_testcases = tree.xpath('.//failure/.. | .//error/..')
if len(failed_testcases) == 0:
log.debug("No failures or errors found in unit test's output xml file.")
testcase1_casename = testcase1.get("name", "test-name")
testcase1_suitename = testcase1.get("classname", "suite-name")
testcase1_msg = f'Test `{testcase1_casename}` of `{testcase1_suitename}` did not pass.'
-
+
for child in testcase1:
if child.tag in ['failure', 'error']:
fault_kind = child.tag.upper()
break
return (error_message + testcase1_msg).replace("\n", " ")
- return f'XML output not found at `{xmlfile_path}`!'
+ else:
+ return f'XML output not found at `{str(xmlfile_path)}`!'
except Exception as exc:
raise Exception("Somthing went wrong while searching for error in XML file: " + repr(exc))
from io import BytesIO
+import os
import paramiko
import socket
run.copy_and_close(b'', MagicMock())
def test_find_unittest_error(self):
- unittest_xml = "xml_files/test_scan_nose.xml"
- error_msg = run.find_unittest_error(unittest_xml)
- assert error_msg == "Total 1 testcase/s did not pass. FAILURE: Test `test_set_bucket_tagging` of `s3tests_boto3.functional.test_s3` because 'NoSuchTagSetError' != 'NoSuchTagSet' -------------------- >> "
+ unittest_xml = os.path.dirname(__file__) + "/xml_files/test_scan_nose.xml"
+ m_ssh = MagicMock()
+ with open(unittest_xml) as xmlfile:
+ m_ssh.exec_command.return_value = (
+ self.m_stdin_buf,
+ xmlfile,
+ self.m_stderr_buf,
+ )
+ error_msg = run.find_unittest_error(unittest_xml, m_ssh)
+ assert error_msg == "Total 1 testcase/s did not pass. FAILURE: Test `test_set_bucket_tagging` of `s3tests_boto3.functional.test_s3` because 'NoSuchTagSetError' != 'NoSuchTagSet' -------------------- >> "
class TestQuote(object):
def test_quote_simple(self):