Best Python code snippet using unittest-xml-reporting_python
testsuite.py
Source:testsuite.py
...174 self.outdir = mkdtemp()175 self.verbosity = 0176 self.runner_kwargs = {}177 self.addCleanup(rmtree, self.outdir)178 def _test_xmlrunner(self, suite, runner=None, outdir=None):179 if outdir is None:180 outdir = self.outdir181 stream = self.stream182 verbosity = self.verbosity183 runner_kwargs = self.runner_kwargs184 if runner is None:185 runner = xmlrunner.XMLTestRunner(186 stream=stream, output=outdir, verbosity=verbosity,187 **runner_kwargs)188 if isinstance(outdir, BytesIO):189 self.assertFalse(outdir.getvalue())190 else:191 self.assertEqual(0, len(glob(os.path.join(outdir, '*xml'))))192 runner.run(suite)193 if isinstance(outdir, BytesIO):194 self.assertTrue(outdir.getvalue())195 else:196 self.assertEqual(1, len(glob(os.path.join(outdir, '*xml'))))197 return runner198 def test_basic_unittest_constructs(self):199 suite = unittest.TestSuite()200 suite.addTest(self.DummyTest('test_pass'))201 suite.addTest(self.DummyTest('test_skip'))202 suite.addTest(self.DummyTest('test_fail'))203 suite.addTest(self.DummyTest('test_expected_failure'))204 suite.addTest(self.DummyTest('test_unexpected_success'))205 suite.addTest(self.DummyTest('test_error'))206 self._test_xmlrunner(suite)207 def test_classnames(self):208 suite = unittest.TestSuite()209 suite.addTest(self.DummyTest('test_pass'))210 suite.addTest(self.DummySubTest('test_subTest_pass'))211 outdir = BytesIO()212 stream = StringIO()213 runner = xmlrunner.XMLTestRunner(214 stream=stream, output=outdir, verbosity=0)215 runner.run(suite)216 outdir.seek(0)217 output = outdir.read()218 output = _strip_xml(output, {219 '//testsuite': (),220 '//testcase': ('classname', 'name'),221 '//failure': ('message',),222 })223 self.assertRegexpMatches(224 output,225 r'classname="tests\.testsuite\.(XMLTestRunnerTestCase\.)?'226 r'DummyTest" name="test_pass"'.encode('utf8'),227 )228 self.assertRegexpMatches(229 output,230 r'classname="tests\.testsuite\.(XMLTestRunnerTestCase\.)?'231 r'DummySubTest" name="test_subTest_pass"'.encode('utf8'),232 )233 def test_expected_failure(self):234 suite = unittest.TestSuite()235 suite.addTest(self.DummyTest('test_expected_failure'))236 outdir = BytesIO()237 self._test_xmlrunner(suite, outdir=outdir)238 self.assertNotIn(b'<failure', outdir.getvalue())239 self.assertNotIn(b'<error', outdir.getvalue())240 self.assertIn(b'<skip', outdir.getvalue())241 def test_unexpected_success(self):242 suite = unittest.TestSuite()243 suite.addTest(self.DummyTest('test_unexpected_success'))244 outdir = BytesIO()245 self._test_xmlrunner(suite, outdir=outdir)246 self.assertNotIn(b'<failure', outdir.getvalue())247 self.assertIn(b'<error', outdir.getvalue())248 self.assertNotIn(b'<skip', outdir.getvalue())249 def test_xmlrunner_non_ascii(self):250 suite = unittest.TestSuite()251 suite.addTest(self.DummyTest('test_non_ascii_skip'))252 suite.addTest(self.DummyTest('test_non_ascii_error'))253 outdir = BytesIO()254 runner = xmlrunner.XMLTestRunner(255 stream=self.stream, output=outdir, verbosity=self.verbosity,256 **self.runner_kwargs)257 runner.run(suite)258 outdir.seek(0)259 output = outdir.read()260 self.assertIn(261 u'message="demonstrating non-ascii skipping: éçà "'.encode('utf8'),262 output)263 def test_xmlrunner_safe_xml_encoding_name(self):264 suite = unittest.TestSuite()265 suite.addTest(self.DummyTest('test_pass'))266 outdir = BytesIO()267 runner = xmlrunner.XMLTestRunner(268 stream=self.stream, output=outdir, verbosity=self.verbosity,269 **self.runner_kwargs)270 runner.run(suite)271 outdir.seek(0)272 output = outdir.read()273 firstline = output.splitlines()[0]274 # test for issue #74275 self.assertIn('encoding="UTF-8"'.encode('utf8'), firstline)276 def test_xmlrunner_check_for_valid_xml_streamout(self):277 """278 This test checks if the xml document is valid if there are more than279 one testsuite and the output of the report is a single stream.280 """281 class DummyTestA(unittest.TestCase):282 def test_pass(self):283 pass284 class DummyTestB(unittest.TestCase):285 def test_pass(self):286 pass287 suite = unittest.TestSuite()288 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestA))289 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestB))290 outdir = BytesIO()291 runner = xmlrunner.XMLTestRunner(292 stream=self.stream, output=outdir, verbosity=self.verbosity,293 **self.runner_kwargs)294 runner.run(suite)295 outdir.seek(0)296 output = outdir.read()297 # Finally check if we have a valid XML document or not.298 try:299 minidom.parseString(output)300 except Exception as e: # pragma: no cover301 # note: we could remove the try/except, but it's more crude.302 self.fail(e)303 def test_xmlrunner_unsafe_unicode(self):304 suite = unittest.TestSuite()305 suite.addTest(self.DummyTest('test_unsafe_unicode'))306 outdir = BytesIO()307 runner = xmlrunner.XMLTestRunner(308 stream=self.stream, output=outdir, verbosity=self.verbosity,309 **self.runner_kwargs)310 runner.run(suite)311 outdir.seek(0)312 output = outdir.read()313 self.assertIn(u"<![CDATA[ABCD\n]]>".encode('utf8'),314 output)315 def test_xmlrunner_non_ascii_failures(self):316 self._xmlrunner_non_ascii_failures()317 def test_xmlrunner_non_ascii_failures_buffered_output(self):318 self._xmlrunner_non_ascii_failures(buffer=True)319 def _xmlrunner_non_ascii_failures(self, buffer=False):320 suite = unittest.TestSuite()321 suite.addTest(self.DummyTest(322 'test_non_ascii_runner_buffer_output_fail'))323 outdir = BytesIO()324 runner = xmlrunner.XMLTestRunner(325 stream=self.stream, output=outdir, verbosity=self.verbosity,326 buffer=buffer, **self.runner_kwargs)327 # allow output non-ascii letters to stdout328 orig_stdout = sys.stdout329 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')330 try:331 runner.run(suite)332 finally:333 # Not to be closed when TextIOWrapper is disposed.334 sys.stdout.detach()335 sys.stdout = orig_stdout336 outdir.seek(0)337 output = outdir.read()338 self.assertIn(339 u'Where is the café ?'.encode('utf8'),340 output)341 self.assertIn(342 u'The café could not be found'.encode('utf8'),343 output)344 @unittest.expectedFailure345 def test_xmlrunner_buffer_output_pass(self):346 suite = unittest.TestSuite()347 suite.addTest(self.DummyTest('test_runner_buffer_output_pass'))348 self._test_xmlrunner(suite)349 testsuite_output = self.stream.getvalue()350 # Since we are always buffering stdout/stderr351 # it is currently troublesome to print anything at all352 # and be consistent with --buffer option (issue #59)353 self.assertIn('should not be printed', testsuite_output)354 # this will be fixed when using the composite approach355 # that was under development in the rewrite branch.356 def test_xmlrunner_buffer_output_fail(self):357 suite = unittest.TestSuite()358 suite.addTest(self.DummyTest('test_runner_buffer_output_fail'))359 # --buffer option360 self.runner_kwargs['buffer'] = True361 self._test_xmlrunner(suite)362 testsuite_output = self.stream.getvalue()363 self.assertIn('should be printed', testsuite_output)364 def test_xmlrunner_output_without_buffer(self):365 suite = unittest.TestSuite()366 suite.addTest(self.DummyTest('test_output'))367 with capture_stdout_stderr() as r:368 self._test_xmlrunner(suite)369 output_from_test = r[0].getvalue()370 self.assertIn('test message', output_from_test)371 def test_xmlrunner_output_with_buffer(self):372 suite = unittest.TestSuite()373 suite.addTest(self.DummyTest('test_output'))374 # --buffer option375 self.runner_kwargs['buffer'] = True376 with capture_stdout_stderr() as r:377 self._test_xmlrunner(suite)378 output_from_test = r[0].getvalue()379 self.assertNotIn('test message', output_from_test)380 def test_xmlrunner_stdout_stderr_recovered_without_buffer(self):381 orig_stdout = sys.stdout382 orig_stderr = sys.stderr383 suite = unittest.TestSuite()384 suite.addTest(self.DummyTest('test_pass'))385 self._test_xmlrunner(suite)386 self.assertIs(orig_stdout, sys.stdout)387 self.assertIs(orig_stderr, sys.stderr)388 def test_xmlrunner_stdout_stderr_recovered_with_buffer(self):389 orig_stdout = sys.stdout390 orig_stderr = sys.stderr391 suite = unittest.TestSuite()392 suite.addTest(self.DummyTest('test_pass'))393 # --buffer option394 self.runner_kwargs['buffer'] = True395 self._test_xmlrunner(suite)396 self.assertIs(orig_stdout, sys.stdout)397 self.assertIs(orig_stderr, sys.stderr)398 suite = unittest.TestSuite()399 suite.addTest(self.DummyTest('test_pass'))400 @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),401 'unittest.TestCase.subTest not present.')402 def test_unittest_subTest_fail(self):403 # test for issue #77404 outdir = BytesIO()405 runner = xmlrunner.XMLTestRunner(406 stream=self.stream, output=outdir, verbosity=self.verbosity,407 **self.runner_kwargs)408 suite = unittest.TestSuite()409 suite.addTest(self.DummySubTest('test_subTest_fail'))410 runner.run(suite)411 outdir.seek(0)412 output = outdir.read()413 output = _strip_xml(output, {414 '//testsuite': (),415 '//testcase': ('classname', 'name'),416 '//failure': ('message',),417 })418 self.assertRegexpMatches(419 output,420 br'<testcase classname="tests\.testsuite\.'421 br'(XMLTestRunnerTestCase\.)?DummySubTest" '422 br'name="test_subTest_fail \(i=0\)"')423 self.assertRegexpMatches(424 output,425 br'<testcase classname="tests\.testsuite\.'426 br'(XMLTestRunnerTestCase\.)?DummySubTest" '427 br'name="test_subTest_fail \(i=1\)"')428 @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),429 'unittest.TestCase.subTest not present.')430 def test_unittest_subTest_error(self):431 # test for issue #155432 outdir = BytesIO()433 runner = xmlrunner.XMLTestRunner(434 stream=self.stream, output=outdir, verbosity=self.verbosity,435 **self.runner_kwargs)436 suite = unittest.TestSuite()437 suite.addTest(self.DummySubTest('test_subTest_error'))438 runner.run(suite)439 outdir.seek(0)440 output = outdir.read()441 output = _strip_xml(output, {442 '//testsuite': (),443 '//testcase': ('classname', 'name'),444 '//failure': ('message',),445 })446 self.assertRegexpMatches(447 output,448 br'<testcase classname="tests\.testsuite\.'449 br'(XMLTestRunnerTestCase\.)?DummySubTest" '450 br'name="test_subTest_error \(i=0\)"')451 self.assertRegexpMatches(452 output,453 br'<testcase classname="tests\.testsuite\.'454 br'(XMLTestRunnerTestCase\.)?DummySubTest" '455 br'name="test_subTest_error \(i=1\)"')456 @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),457 'unittest.TestCase.subTest not present.')458 def test_unittest_subTest_mixed(self):459 # test for issue #155460 outdir = BytesIO()461 runner = xmlrunner.XMLTestRunner(462 stream=self.stream, output=outdir, verbosity=self.verbosity,463 **self.runner_kwargs)464 suite = unittest.TestSuite()465 suite.addTest(self.DummySubTest('test_subTest_mixed'))466 runner.run(suite)467 outdir.seek(0)468 output = outdir.read()469 output = _strip_xml(output, {470 '//testsuite': (),471 '//testcase': ('classname', 'name'),472 '//failure': ('message',),473 })474 self.assertNotIn(475 'name="test_subTest_mixed (i=0)"'.encode('utf8'),476 output)477 self.assertIn(478 'name="test_subTest_mixed (i=1)"'.encode('utf8'),479 output)480 @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),481 'unittest.TestCase.subTest not present.')482 def test_unittest_subTest_pass(self):483 # Test for issue #85484 suite = unittest.TestSuite()485 suite.addTest(self.DummySubTest('test_subTest_pass'))486 self._test_xmlrunner(suite)487 @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),488 'unittest.TestCase.subTest not present.')489 def test_unittest_subTest_with_dots(self):490 # Test for issue #85491 suite = unittest.TestSuite()492 suite.addTest(self.DummySubTest('test_subTest_with_dots'))493 outdir = BytesIO()494 self._test_xmlrunner(suite, outdir=outdir)495 xmlcontent = outdir.getvalue().decode()496 # Method name497 self.assertNotIn('name="subTest', xmlcontent, 'parsing of test method name is not done correctly')498 self.assertIn('name="test_subTest_with_dots (module=\'hello.world.subTest', xmlcontent)499 # Class name500 matchString = 'classname="tests.testsuite.XMLTestRunnerTestCase.DummySubTest.test_subTest_with_dots (module=\'hello.world"'501 self.assertNotIn(matchString, xmlcontent, 'parsing of class name is not done correctly')502 self.assertIn('classname="tests.testsuite.XMLTestRunnerTestCase.DummySubTest"', xmlcontent)503 def test_xmlrunner_pass(self):504 suite = unittest.TestSuite()505 suite.addTest(self.DummyTest('test_pass'))506 self._test_xmlrunner(suite)507 def test_xmlrunner_failfast(self):508 suite = unittest.TestSuite()509 suite.addTest(self.DummyTest('test_fail'))510 suite.addTest(self.DummyTest('test_pass'))511 outdir = BytesIO()512 runner = xmlrunner.XMLTestRunner(513 stream=self.stream, output=outdir,514 verbosity=self.verbosity, failfast=True,515 **self.runner_kwargs)516 runner.run(suite)517 outdir.seek(0)518 output = outdir.read()519 self.assertIn('test_fail'.encode('utf8'), output)520 self.assertNotIn('test_pass'.encode('utf8'), output)521 def test_xmlrunner_verbose(self):522 self.verbosity = 1523 suite = unittest.TestSuite()524 suite.addTest(self.DummyTest('test_pass'))525 self._test_xmlrunner(suite)526 def test_xmlrunner_showall(self):527 self.verbosity = 2528 suite = unittest.TestSuite()529 suite.addTest(self.DummyTest('test_pass'))530 self._test_xmlrunner(suite)531 def test_xmlrunner_cdata_section(self):532 suite = unittest.TestSuite()533 suite.addTest(self.DummyTest('test_cdata_section'))534 self._test_xmlrunner(suite)535 def test_xmlrunner_invalid_xml_chars_in_doc(self):536 suite = unittest.TestSuite()537 suite.addTest(self.DummyTest('test_invalid_xml_chars_in_doc'))538 outdir = BytesIO()539 runner = xmlrunner.XMLTestRunner(540 stream=self.stream, output=outdir, verbosity=self.verbosity,541 **self.runner_kwargs)542 runner.run(suite)543 outdir.seek(0)544 output = outdir.read()545 # Finally check if we have a valid XML document or not.546 try:547 minidom.parseString(output)548 except Exception as e: # pragma: no cover549 # note: we could remove the try/except, but it's more crude.550 self.fail(e)551 def test_xmlrunner_outsuffix(self):552 self.runner_kwargs['outsuffix'] = '.somesuffix'553 suite = unittest.TestSuite()554 suite.addTest(self.DummyTest('test_pass'))555 self._test_xmlrunner(suite)556 xmlfile = glob(os.path.join(self.outdir, '*xml'))[0]557 assert xmlfile.endswith('.somesuffix.xml')558 def test_xmlrunner_nosuffix(self):559 self.runner_kwargs['outsuffix'] = ''560 suite = unittest.TestSuite()561 suite.addTest(self.DummyTest('test_pass'))562 self._test_xmlrunner(suite)563 xmlfile = glob(os.path.join(self.outdir, '*xml'))[0]564 xmlfile = os.path.basename(xmlfile)565 assert xmlfile.endswith('DummyTest.xml')566 def test_junitxml_properties(self):567 suite = unittest.TestSuite()568 suite.addTest(self.DummyTest('test_pass'))569 suite.properties = dict(key='value')570 self._test_xmlrunner(suite)571 def test_junitxml_xsd_validation_order(self):572 suite = unittest.TestSuite()573 suite.addTest(self.DummyTest('test_fail'))574 suite.addTest(self.DummyTest('test_pass'))575 suite.addTest(self.DummyTest('test_output_stdout_and_stderr'))576 suite.properties = dict(key='value')577 outdir = BytesIO()578 runner = xmlrunner.XMLTestRunner(579 stream=self.stream, output=outdir, verbosity=self.verbosity,580 **self.runner_kwargs)581 runner.run(suite)582 outdir.seek(0)583 output = outdir.read()584 # poor man's schema validation; see issue #90585 i_properties = output.index('<properties>'.encode('utf8'))586 i_system_out = output.index('<system-out>'.encode('utf8'))587 i_system_err = output.index('<system-err>'.encode('utf8'))588 i_testcase = output.index('<testcase'.encode('utf8'))589 self.assertTrue(i_properties < i_testcase <590 i_system_out < i_system_err)591 # XSD validation - for good measure.592 validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', output)593 def test_junitxml_xsd_validation_empty_properties(self):594 suite = unittest.TestSuite()595 suite.addTest(self.DummyTest('test_fail'))596 suite.addTest(self.DummyTest('test_pass'))597 suite.properties = None598 outdir = BytesIO()599 runner = xmlrunner.XMLTestRunner(600 stream=self.stream, output=outdir, verbosity=self.verbosity,601 **self.runner_kwargs)602 runner.run(suite)603 outdir.seek(0)604 output = outdir.read()605 self.assertNotIn('<properties>'.encode('utf8'), output)606 validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', output)607 @unittest.skipIf(hasattr(sys, 'pypy_version_info'),608 'skip - PyPy + lxml seems to be hanging')609 def test_xunit_plugin_transform(self):610 suite = unittest.TestSuite()611 suite.addTest(self.DummyTest('test_fail'))612 suite.addTest(self.DummyTest('test_pass'))613 suite.properties = None614 outdir = BytesIO()615 runner = xmlrunner.XMLTestRunner(616 stream=self.stream, output=outdir, verbosity=self.verbosity,617 **self.runner_kwargs)618 runner.run(suite)619 outdir.seek(0)620 output = outdir.read()621 validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', output)622 with self.assertRaises(etree.DocumentInvalid):623 validate_junit_report('ae25da5089d4f94ac6c4669bf736e4d416cc4665', output)624 from xmlrunner.extra.xunit_plugin import transform625 transformed = transform(output)626 validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', transformed)627 validate_junit_report('ae25da5089d4f94ac6c4669bf736e4d416cc4665', transformed)628 self.assertIn('test_pass'.encode('utf8'), transformed)629 self.assertIn('test_fail'.encode('utf8'), transformed)630 def test_xmlrunner_elapsed_times(self):631 self.runner_kwargs['elapsed_times'] = False632 suite = unittest.TestSuite()633 suite.addTest(self.DummyTest('test_pass'))634 self._test_xmlrunner(suite)635 def test_xmlrunner_resultclass(self):636 class Result(_XMLTestResult):637 pass638 suite = unittest.TestSuite()639 suite.addTest(self.DummyTest('test_pass'))640 self.runner_kwargs['resultclass'] = Result641 self._test_xmlrunner(suite)642 def test_xmlrunner_stream(self):643 stream = self.stream644 output = BytesIO()645 runner = xmlrunner.XMLTestRunner(646 stream=stream, output=output, verbosity=self.verbosity,647 **self.runner_kwargs)648 suite = unittest.TestSuite()649 suite.addTest(self.DummyTest('test_pass'))650 runner.run(suite)651 def test_xmlrunner_stream_empty_testsuite(self):652 stream = self.stream653 output = BytesIO()654 runner = xmlrunner.XMLTestRunner(655 stream=stream, output=output, verbosity=self.verbosity,656 **self.runner_kwargs)657 suite = unittest.TestSuite()658 runner.run(suite)659 def test_xmlrunner_output_subdir(self):660 stream = self.stream661 output = os.path.join(self.outdir, 'subdir')662 runner = xmlrunner.XMLTestRunner(663 stream=stream, output=output, verbosity=self.verbosity,664 **self.runner_kwargs)665 suite = unittest.TestSuite()666 suite.addTest(self.DummyTest('test_pass'))667 runner.run(suite)668 def test_xmlrunner_patched_stdout(self):669 old_stdout, old_stderr = sys.stdout, sys.stderr670 try:671 sys.stdout, sys.stderr = StringIO(), StringIO()672 suite = unittest.TestSuite()673 suite.addTest(self.DummyTest('test_pass'))674 suite.properties = dict(key='value')675 self._test_xmlrunner(suite)676 finally:677 sys.stdout, sys.stderr = old_stdout, old_stderr678 def test_opaque_decorator(self):679 suite = unittest.TestSuite()680 suite.addTest(self.DecoratedUnitTest('test_pass'))681 self._test_xmlrunner(suite)682 testsuite_output = self.stream.getvalue()683 self.assertNotIn('IOError:', testsuite_output)684 def test_xmlrunner_error_in_call(self):685 suite = unittest.TestSuite()686 suite.addTest(self.DummyErrorInCallTest('test_pass'))687 self._test_xmlrunner(suite)688 testsuite_output = self.stream.getvalue()689 self.assertIn('Exception: Massive fail', testsuite_output)690 @unittest.skipIf(not hasattr(sys, 'getrefcount'),691 'skip - PyPy does not have sys.getrefcount.')692 @unittest.skipIf((3, 0) <= sys.version_info < (3, 4),693 'skip - test not garbage collected. '694 'https://bugs.python.org/issue11798.')695 def test_xmlrunner_hold_traceback(self):696 suite = unittest.TestSuite()697 suite.addTest(self.DummyRefCountTest('test_fail'))698 countBeforeTest = sys.getrefcount(self.DummyRefCountTest.dummy)699 runner = self._test_xmlrunner(suite)700 countAfterTest = sys.getrefcount(self.DummyRefCountTest.dummy)701 self.assertEqual(countBeforeTest, countAfterTest)702 class StderrXMLTestRunner(xmlrunner.XMLTestRunner):703 """704 XMLTestRunner that outputs to sys.stderr that might be replaced705 Though XMLTestRunner defaults to use sys.stderr as stream,706 it cannot be replaced e.g. by replaced by capture_stdout_stderr(),707 as it's already resolved.708 This class resolved sys.stderr lazily and outputs to replaced sys.stderr.709 """710 def __init__(self, **kwargs):711 super(XMLTestRunnerTestCase.StderrXMLTestRunner, self).__init__(712 stream=sys.stderr,713 **kwargs714 )715 def test_test_program_succeed_with_buffer(self):716 with capture_stdout_stderr() as r:717 unittest.TestProgram(718 module=self.__class__.__module__,719 testRunner=self.StderrXMLTestRunner,720 argv=[721 sys.argv[0],722 '-b',723 'XMLTestRunnerTestCase.DummyTest.test_runner_buffer_output_pass',724 ],725 exit=False,726 )727 self.assertNotIn('should not be printed', r[0].getvalue())728 self.assertNotIn('should not be printed', r[1].getvalue())729 def test_test_program_succeed_wo_buffer(self):730 with capture_stdout_stderr() as r:731 unittest.TestProgram(732 module=self.__class__.__module__,733 testRunner=self.StderrXMLTestRunner,734 argv=[735 sys.argv[0],736 'XMLTestRunnerTestCase.DummyTest.test_runner_buffer_output_pass',737 ],738 exit=False,739 )740 self.assertIn('should not be printed', r[0].getvalue())741 self.assertNotIn('should not be printed', r[1].getvalue())742 def test_test_program_fail_with_buffer(self):743 with capture_stdout_stderr() as r:744 unittest.TestProgram(745 module=self.__class__.__module__,746 testRunner=self.StderrXMLTestRunner,747 argv=[748 sys.argv[0],749 '-b',750 'XMLTestRunnerTestCase.DummyTest.test_runner_buffer_output_fail',751 ],752 exit=False,753 )754 self.assertNotIn('should be printed', r[0].getvalue())755 self.assertIn('should be printed', r[1].getvalue())756 def test_test_program_fail_wo_buffer(self):757 with capture_stdout_stderr() as r:758 unittest.TestProgram(759 module=self.__class__.__module__,760 testRunner=self.StderrXMLTestRunner,761 argv=[762 sys.argv[0],763 'XMLTestRunnerTestCase.DummyTest.test_runner_buffer_output_fail',764 ],765 exit=False,766 )767 self.assertIn('should be printed', r[0].getvalue())768 self.assertNotIn('should be printed', r[1].getvalue())769 def test_partialmethod(self):770 from functools import partialmethod771 def test_partialmethod(test):772 pass773 class TestWithPartialmethod(unittest.TestCase):774 pass775 setattr(776 TestWithPartialmethod,777 'test_partialmethod',778 partialmethod(test_partialmethod),779 )780 suite = unittest.TestSuite()781 suite.addTest(TestWithPartialmethod('test_partialmethod'))782 self._test_xmlrunner(suite)783class DuplicateWriterTestCase(unittest.TestCase):784 def setUp(self):785 fd, self.file = mkstemp()786 self.fh = os.fdopen(fd, 'w')787 self.buffer = StringIO()788 self.writer = _DuplicateWriter(self.fh, self.buffer)789 def tearDown(self):790 self.buffer.close()791 self.fh.close()792 os.unlink(self.file)793 def getFirstContent(self):794 with open(self.file, 'r') as f:795 return f.read()796 def getSecondContent(self):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!