How to use _createCDATAsections method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

result.py

Source:result.py Github

copy

Full Screen

...297 for test in tests:298 # Merge the stdout from the tests in a class299 if test.stdout is not None:300 stdout.write(test.stdout)301 _XMLTestResult._createCDATAsections(302 xml_document, systemout, stdout.getvalue())303 systemerr = xml_document.createElement('system-err')304 testsuite.appendChild(systemerr)305 stderr = StringIO()306 for test in tests:307 # Merge the stderr from the tests in a class308 if test.stderr is not None:309 stderr.write(test.stderr)310 _XMLTestResult._createCDATAsections(311 xml_document, systemerr, stderr.getvalue())312 return testsuite313 _report_testsuite = staticmethod(_report_testsuite)314 def _test_method_name(test_id):315 """316 Returns the test method name.317 """318 return test_id.split('.')[-1]319 _test_method_name = staticmethod(_test_method_name)320 def _createCDATAsections(xmldoc, node, text):321 text = safe_unicode(text)322 pos = text.find(']]>')323 while pos >= 0:324 tmp = text[0:pos+2]325 cdata = xmldoc.createCDATASection(tmp)326 node.appendChild(cdata)327 text = text[pos+2:]328 pos = text.find(']]>')329 cdata = xmldoc.createCDATASection(text)330 node.appendChild(cdata)331 _createCDATAsections = staticmethod(_createCDATAsections)332 def _report_testcase(test_result, xml_testsuite, xml_document):333 """334 Appends a testcase section to the XML document.335 """336 testcase = xml_document.createElement('testcase')337 xml_testsuite.appendChild(testcase)338 class_name = re.sub(r'^__main__.', '', test_result.id())339 class_name = class_name.rpartition('.')[0]340 testcase.setAttribute('classname', class_name)341 testcase.setAttribute(342 'name', _XMLTestResult._test_method_name(test_result.test_id)343 )344 testcase.setAttribute('time', '%.3f' % test_result.elapsed_time)345 if (test_result.outcome != test_result.SUCCESS):346 elem_name = ('failure', 'error', 'skipped')[test_result.outcome-1]347 failure = xml_document.createElement(elem_name)348 testcase.appendChild(failure)349 if test_result.outcome != test_result.SKIP:350 failure.setAttribute(351 'type',352 safe_unicode(test_result.err[0].__name__)353 )354 failure.setAttribute(355 'message',356 safe_unicode(test_result.err[1])357 )358 error_info = safe_unicode(test_result.get_error_info())359 _XMLTestResult._createCDATAsections(360 xml_document, failure, error_info)361 else:362 failure.setAttribute('type', 'skip')363 failure.setAttribute('message', safe_unicode(test_result.err))364 _report_testcase = staticmethod(_report_testcase)365 def generate_reports(self, test_runner):366 """367 Generates the XML reports to a given XMLTestRunner object.368 """369 from xml.dom.minidom import Document370 all_results = self._get_info_by_testcase()371 outputHandledAsString = \372 isinstance(test_runner.output, six.string_types)373 if (outputHandledAsString and not os.path.exists(test_runner.output)):...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...241 stdout = StringIO()242 for test in tests:243 # Merge the stdout from the tests in a class244 stdout.write(test.stdout)245 _XMLTestResult._createCDATAsections(xml_document, systemout, stdout.getvalue())246 systemerr = xml_document.createElement('system-err')247 testsuite.appendChild(systemerr)248 stderr = StringIO()249 for test in tests:250 # Merge the stderr from the tests in a class251 stderr.write(test.stderr)252 _XMLTestResult._createCDATAsections(xml_document, systemerr, stderr.getvalue())253 return testsuite254 _report_testsuite = staticmethod(_report_testsuite)255 def _test_method_name(test_id):256 """257 Returns the test method name.258 """259 return test_id.split('.')[-1]260 _test_method_name = staticmethod(_test_method_name)261 def _createCDATAsections(xmldoc, node, text):262 pos = text.find(']]>')263 while pos >= 0:264 tmp=text[0:pos+2]265 cdata = xmldoc.createCDATASection(tmp)266 node.appendChild(cdata)267 text=text[pos+2:]268 pos = text.find(']]>')269 cdata = xmldoc.createCDATASection(text)270 node.appendChild(cdata)271 _createCDATAsections = staticmethod(_createCDATAsections)272 def _report_testcase(suite_name, test_result, xml_testsuite, xml_document):273 """274 Appends a testcase section to the XML document.275 """276 testcase = xml_document.createElement('testcase')277 xml_testsuite.appendChild(testcase)278 testcase.setAttribute('classname', suite_name)279 testcase.setAttribute(280 'name', _XMLTestResult._test_method_name(test_result.test_id)281 )282 testcase.setAttribute('time', '%.3f' % test_result.elapsed_time)283 if (test_result.outcome != _TestInfo.SUCCESS):284 elem_name = ('failure', 'error', 'skipped')[test_result.outcome - 1]285 failure = xml_document.createElement(elem_name)286 testcase.appendChild(failure)287 if test_result.outcome != _TestInfo.SKIP:288 failure.setAttribute('type', test_result.err[0].__name__)289 failure.setAttribute('message', to_unicode(test_result.err[1]))290 error_info = to_unicode(test_result.get_error_info())291 _XMLTestResult._createCDATAsections(xml_document, failure, error_info)292 else:293 failure.setAttribute('type', 'skip')294 failure.setAttribute('message', to_unicode(test_result.err))295 _report_testcase = staticmethod(_report_testcase)296 def generate_reports(self, test_runner):297 """298 Generates the XML reports to a given XMLTestRunner object.299 """300 from xml.dom.minidom import Document301 all_results = self._get_info_by_testcase(test_runner.outsuffix)302 if (isinstance(test_runner.output, six.string_types) and not303 os.path.exists(test_runner.output)):304 os.makedirs(test_runner.output)305 for suite, tests in all_results.items():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unittest-xml-reporting automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful