How to use stopTest method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

test_skipping.py

Source:test_skipping.py Github

copy

Full Screen

1import unittest2from unittest.test.support import LoggingResult3class Test_TestSkipping(unittest.TestCase):4 def test_skipping(self):5 class Foo(unittest.TestCase):6 def defaultTestResult(self):7 return LoggingResult(events)8 def test_skip_me(self):9 self.skipTest("skip")10 events = []11 result = LoggingResult(events)12 test = Foo("test_skip_me")13 self.assertIs(test.run(result), result)14 self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])15 self.assertEqual(result.skipped, [(test, "skip")])16 events = []17 result = test.run()18 self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',19 'stopTest', 'stopTestRun'])20 self.assertEqual(result.skipped, [(test, "skip")])21 self.assertEqual(result.testsRun, 1)22 # Try letting setUp skip the test now.23 class Foo(unittest.TestCase):24 def defaultTestResult(self):25 return LoggingResult(events)26 def setUp(self):27 self.skipTest("testing")28 def test_nothing(self): pass29 events = []30 result = LoggingResult(events)31 test = Foo("test_nothing")32 self.assertIs(test.run(result), result)33 self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])34 self.assertEqual(result.skipped, [(test, "testing")])35 self.assertEqual(result.testsRun, 1)36 events = []37 result = test.run()38 self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',39 'stopTest', 'stopTestRun'])40 self.assertEqual(result.skipped, [(test, "testing")])41 self.assertEqual(result.testsRun, 1)42 def test_skipping_subtests(self):43 class Foo(unittest.TestCase):44 def defaultTestResult(self):45 return LoggingResult(events)46 def test_skip_me(self):47 with self.subTest(a=1):48 with self.subTest(b=2):49 self.skipTest("skip 1")50 self.skipTest("skip 2")51 self.skipTest("skip 3")52 events = []53 result = LoggingResult(events)54 test = Foo("test_skip_me")55 self.assertIs(test.run(result), result)56 self.assertEqual(events, ['startTest', 'addSkip', 'addSkip',57 'addSkip', 'stopTest'])58 self.assertEqual(len(result.skipped), 3)59 subtest, msg = result.skipped[0]60 self.assertEqual(msg, "skip 1")61 self.assertIsInstance(subtest, unittest.TestCase)62 self.assertIsNot(subtest, test)63 subtest, msg = result.skipped[1]64 self.assertEqual(msg, "skip 2")65 self.assertIsInstance(subtest, unittest.TestCase)66 self.assertIsNot(subtest, test)67 self.assertEqual(result.skipped[2], (test, "skip 3"))68 events = []69 result = test.run()70 self.assertEqual(events,71 ['startTestRun', 'startTest', 'addSkip', 'addSkip',72 'addSkip', 'stopTest', 'stopTestRun'])73 self.assertEqual([msg for subtest, msg in result.skipped],74 ['skip 1', 'skip 2', 'skip 3'])75 def test_skipping_decorators(self):76 op_table = ((unittest.skipUnless, False, True),77 (unittest.skipIf, True, False))78 for deco, do_skip, dont_skip in op_table:79 class Foo(unittest.TestCase):80 def defaultTestResult(self):81 return LoggingResult(events)82 @deco(do_skip, "testing")83 def test_skip(self): pass84 @deco(dont_skip, "testing")85 def test_dont_skip(self): pass86 test_do_skip = Foo("test_skip")87 test_dont_skip = Foo("test_dont_skip")88 suite = unittest.TestSuite([test_do_skip, test_dont_skip])89 events = []90 result = LoggingResult(events)91 self.assertIs(suite.run(result), result)92 self.assertEqual(len(result.skipped), 1)93 expected = ['startTest', 'addSkip', 'stopTest',94 'startTest', 'addSuccess', 'stopTest']95 self.assertEqual(events, expected)96 self.assertEqual(result.testsRun, 2)97 self.assertEqual(result.skipped, [(test_do_skip, "testing")])98 self.assertTrue(result.wasSuccessful())99 events = []100 result = test_do_skip.run()101 self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',102 'stopTest', 'stopTestRun'])103 self.assertEqual(result.skipped, [(test_do_skip, "testing")])104 events = []105 result = test_dont_skip.run()106 self.assertEqual(events, ['startTestRun', 'startTest', 'addSuccess',107 'stopTest', 'stopTestRun'])108 self.assertEqual(result.skipped, [])109 def test_skip_class(self):110 @unittest.skip("testing")111 class Foo(unittest.TestCase):112 def defaultTestResult(self):113 return LoggingResult(events)114 def test_1(self):115 record.append(1)116 events = []117 record = []118 result = LoggingResult(events)119 test = Foo("test_1")120 suite = unittest.TestSuite([test])121 self.assertIs(suite.run(result), result)122 self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])123 self.assertEqual(result.skipped, [(test, "testing")])124 self.assertEqual(record, [])125 events = []126 result = test.run()127 self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',128 'stopTest', 'stopTestRun'])129 self.assertEqual(result.skipped, [(test, "testing")])130 self.assertEqual(record, [])131 def test_skip_non_unittest_class(self):132 @unittest.skip("testing")133 class Mixin:134 def test_1(self):135 record.append(1)136 class Foo(Mixin, unittest.TestCase):137 pass138 record = []139 result = unittest.TestResult()140 test = Foo("test_1")141 suite = unittest.TestSuite([test])142 self.assertIs(suite.run(result), result)143 self.assertEqual(result.skipped, [(test, "testing")])144 self.assertEqual(record, [])145 def test_skip_in_setup(self):146 class Foo(unittest.TestCase):147 def setUp(self):148 self.skipTest("skip")149 def test_skip_me(self):150 self.fail("shouldn't come here")151 events = []152 result = LoggingResult(events)153 test = Foo("test_skip_me")154 self.assertIs(test.run(result), result)155 self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])156 self.assertEqual(result.skipped, [(test, "skip")])157 def test_skip_in_cleanup(self):158 class Foo(unittest.TestCase):159 def test_skip_me(self):160 pass161 def tearDown(self):162 self.skipTest("skip")163 events = []164 result = LoggingResult(events)165 test = Foo("test_skip_me")166 self.assertIs(test.run(result), result)167 self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])168 self.assertEqual(result.skipped, [(test, "skip")])169 def test_failure_and_skip_in_cleanup(self):170 class Foo(unittest.TestCase):171 def test_skip_me(self):172 self.fail("fail")173 def tearDown(self):174 self.skipTest("skip")175 events = []176 result = LoggingResult(events)177 test = Foo("test_skip_me")178 self.assertIs(test.run(result), result)179 self.assertEqual(events, ['startTest', 'addSkip', 'addFailure', 'stopTest'])180 self.assertEqual(result.skipped, [(test, "skip")])181 def test_skipping_and_fail_in_cleanup(self):182 class Foo(unittest.TestCase):183 def test_skip_me(self):184 self.skipTest("skip")185 def tearDown(self):186 self.fail("fail")187 events = []188 result = LoggingResult(events)189 test = Foo("test_skip_me")190 self.assertIs(test.run(result), result)191 self.assertEqual(events, ['startTest', 'addSkip', 'addFailure', 'stopTest'])192 self.assertEqual(result.skipped, [(test, "skip")])193 def test_expected_failure(self):194 class Foo(unittest.TestCase):195 @unittest.expectedFailure196 def test_die(self):197 self.fail("help me!")198 events = []199 result = LoggingResult(events)200 test = Foo("test_die")201 self.assertIs(test.run(result), result)202 self.assertEqual(events,203 ['startTest', 'addExpectedFailure', 'stopTest'])204 self.assertFalse(result.failures)205 self.assertEqual(result.expectedFailures[0][0], test)206 self.assertFalse(result.unexpectedSuccesses)207 self.assertTrue(result.wasSuccessful())208 def test_expected_failure_with_wrapped_class(self):209 @unittest.expectedFailure210 class Foo(unittest.TestCase):211 def test_1(self):212 self.assertTrue(False)213 events = []214 result = LoggingResult(events)215 test = Foo("test_1")216 self.assertIs(test.run(result), result)217 self.assertEqual(events,218 ['startTest', 'addExpectedFailure', 'stopTest'])219 self.assertFalse(result.failures)220 self.assertEqual(result.expectedFailures[0][0], test)221 self.assertFalse(result.unexpectedSuccesses)222 self.assertTrue(result.wasSuccessful())223 def test_expected_failure_with_wrapped_subclass(self):224 class Foo(unittest.TestCase):225 def test_1(self):226 self.assertTrue(False)227 @unittest.expectedFailure228 class Bar(Foo):229 pass230 events = []231 result = LoggingResult(events)232 test = Bar("test_1")233 self.assertIs(test.run(result), result)234 self.assertEqual(events,235 ['startTest', 'addExpectedFailure', 'stopTest'])236 self.assertFalse(result.failures)237 self.assertEqual(result.expectedFailures[0][0], test)238 self.assertFalse(result.unexpectedSuccesses)239 self.assertTrue(result.wasSuccessful())240 def test_expected_failure_subtests(self):241 # A failure in any subtest counts as the expected failure of the242 # whole test.243 class Foo(unittest.TestCase):244 @unittest.expectedFailure245 def test_die(self):246 with self.subTest():247 # This one succeeds248 pass249 with self.subTest():250 self.fail("help me!")251 with self.subTest():252 # This one doesn't get executed253 self.fail("shouldn't come here")254 events = []255 result = LoggingResult(events)256 test = Foo("test_die")257 self.assertIs(test.run(result), result)258 self.assertEqual(events,259 ['startTest', 'addSubTestSuccess',260 'addExpectedFailure', 'stopTest'])261 self.assertFalse(result.failures)262 self.assertEqual(len(result.expectedFailures), 1)263 self.assertIs(result.expectedFailures[0][0], test)264 self.assertFalse(result.unexpectedSuccesses)265 self.assertTrue(result.wasSuccessful())266 def test_expected_failure_and_fail_in_cleanup(self):267 class Foo(unittest.TestCase):268 @unittest.expectedFailure269 def test_die(self):270 self.fail("help me!")271 def tearDown(self):272 self.fail("bad tearDown")273 events = []274 result = LoggingResult(events)275 test = Foo("test_die")276 self.assertIs(test.run(result), result)277 self.assertEqual(events,278 ['startTest', 'addFailure', 'stopTest'])279 self.assertEqual(len(result.failures), 1)280 self.assertIn('AssertionError: bad tearDown', result.failures[0][1])281 self.assertFalse(result.expectedFailures)282 self.assertFalse(result.unexpectedSuccesses)283 self.assertFalse(result.wasSuccessful())284 def test_expected_failure_and_skip_in_cleanup(self):285 class Foo(unittest.TestCase):286 @unittest.expectedFailure287 def test_die(self):288 self.fail("help me!")289 def tearDown(self):290 self.skipTest("skip")291 events = []292 result = LoggingResult(events)293 test = Foo("test_die")294 self.assertIs(test.run(result), result)295 self.assertEqual(events,296 ['startTest', 'addSkip', 'stopTest'])297 self.assertFalse(result.failures)298 self.assertFalse(result.expectedFailures)299 self.assertFalse(result.unexpectedSuccesses)300 self.assertEqual(result.skipped, [(test, "skip")])301 self.assertTrue(result.wasSuccessful())302 def test_unexpected_success(self):303 class Foo(unittest.TestCase):304 @unittest.expectedFailure305 def test_die(self):306 pass307 events = []308 result = LoggingResult(events)309 test = Foo("test_die")310 self.assertIs(test.run(result), result)311 self.assertEqual(events,312 ['startTest', 'addUnexpectedSuccess', 'stopTest'])313 self.assertFalse(result.failures)314 self.assertFalse(result.expectedFailures)315 self.assertEqual(result.unexpectedSuccesses, [test])316 self.assertFalse(result.wasSuccessful())317 def test_unexpected_success_subtests(self):318 # Success in all subtests counts as the unexpected success of319 # the whole test.320 class Foo(unittest.TestCase):321 @unittest.expectedFailure322 def test_die(self):323 with self.subTest():324 # This one succeeds325 pass326 with self.subTest():327 # So does this one328 pass329 events = []330 result = LoggingResult(events)331 test = Foo("test_die")332 self.assertIs(test.run(result), result)333 self.assertEqual(events,334 ['startTest',335 'addSubTestSuccess', 'addSubTestSuccess',336 'addUnexpectedSuccess', 'stopTest'])337 self.assertFalse(result.failures)338 self.assertFalse(result.expectedFailures)339 self.assertEqual(result.unexpectedSuccesses, [test])340 self.assertFalse(result.wasSuccessful())341 def test_unexpected_success_and_fail_in_cleanup(self):342 class Foo(unittest.TestCase):343 @unittest.expectedFailure344 def test_die(self):345 pass346 def tearDown(self):347 self.fail("bad tearDown")348 events = []349 result = LoggingResult(events)350 test = Foo("test_die")351 self.assertIs(test.run(result), result)352 self.assertEqual(events,353 ['startTest', 'addFailure', 'stopTest'])354 self.assertEqual(len(result.failures), 1)355 self.assertIn('AssertionError: bad tearDown', result.failures[0][1])356 self.assertFalse(result.expectedFailures)357 self.assertFalse(result.unexpectedSuccesses)358 self.assertFalse(result.wasSuccessful())359 def test_unexpected_success_and_skip_in_cleanup(self):360 class Foo(unittest.TestCase):361 @unittest.expectedFailure362 def test_die(self):363 pass364 def tearDown(self):365 self.skipTest("skip")366 events = []367 result = LoggingResult(events)368 test = Foo("test_die")369 self.assertIs(test.run(result), result)370 self.assertEqual(events,371 ['startTest', 'addSkip', 'stopTest'])372 self.assertFalse(result.failures)373 self.assertFalse(result.expectedFailures)374 self.assertFalse(result.unexpectedSuccesses)375 self.assertEqual(result.skipped, [(test, "skip")])376 self.assertTrue(result.wasSuccessful())377 def test_skip_doesnt_run_setup(self):378 class Foo(unittest.TestCase):379 wasSetUp = False380 wasTornDown = False381 def setUp(self):382 Foo.wasSetUp = True383 def tornDown(self):384 Foo.wasTornDown = True385 @unittest.skip('testing')386 def test_1(self):387 pass388 result = unittest.TestResult()389 test = Foo("test_1")390 suite = unittest.TestSuite([test])391 self.assertIs(suite.run(result), result)392 self.assertEqual(result.skipped, [(test, "testing")])393 self.assertFalse(Foo.wasSetUp)394 self.assertFalse(Foo.wasTornDown)395 def test_decorated_skip(self):396 def decorator(func):397 def inner(*a):398 return func(*a)399 return inner400 class Foo(unittest.TestCase):401 @decorator402 @unittest.skip('testing')403 def test_1(self):404 pass405 result = unittest.TestResult()406 test = Foo("test_1")407 suite = unittest.TestSuite([test])408 self.assertIs(suite.run(result), result)409 self.assertEqual(result.skipped, [(test, "testing")])410 def test_skip_without_reason(self):411 class Foo(unittest.TestCase):412 @unittest.skip413 def test_1(self):414 pass415 result = unittest.TestResult()416 test = Foo("test_1")417 suite = unittest.TestSuite([test])418 self.assertIs(suite.run(result), result)419 self.assertEqual(result.skipped, [(test, "")])420 def test_debug_skipping(self):421 class Foo(unittest.TestCase):422 def setUp(self):423 events.append("setUp")424 def tearDown(self):425 events.append("tearDown")426 def test1(self):427 self.skipTest('skipping exception')428 events.append("test1")429 @unittest.skip("skipping decorator")430 def test2(self):431 events.append("test2")432 events = []433 test = Foo("test1")434 with self.assertRaises(unittest.SkipTest) as cm:435 test.debug()436 self.assertIn("skipping exception", str(cm.exception))437 self.assertEqual(events, ["setUp"])438 events = []439 test = Foo("test2")440 with self.assertRaises(unittest.SkipTest) as cm:441 test.debug()442 self.assertIn("skipping decorator", str(cm.exception))443 self.assertEqual(events, [])444 def test_debug_skipping_class(self):445 @unittest.skip("testing")446 class Foo(unittest.TestCase):447 def setUp(self):448 events.append("setUp")449 def tearDown(self):450 events.append("tearDown")451 def test(self):452 events.append("test")453 events = []454 test = Foo("test")455 with self.assertRaises(unittest.SkipTest) as cm:456 test.debug()457 self.assertIn("testing", str(cm.exception))458 self.assertEqual(events, [])459 def test_debug_skipping_subtests(self):460 class Foo(unittest.TestCase):461 def setUp(self):462 events.append("setUp")463 def tearDown(self):464 events.append("tearDown")465 def test(self):466 with self.subTest(a=1):467 events.append('subtest')468 self.skipTest("skip subtest")469 events.append('end subtest')470 events.append('end test')471 events = []472 result = LoggingResult(events)473 test = Foo("test")474 with self.assertRaises(unittest.SkipTest) as cm:475 test.debug()476 self.assertIn("skip subtest", str(cm.exception))477 self.assertEqual(events, ['setUp', 'subtest'])478if __name__ == "__main__":...

Full Screen

Full Screen

test_test_results.py

Source:test_test_results.py Github

copy

Full Screen

...69 def test_startTest(self):70 self.result.startTest(self)71 def test_startTestRun(self):72 self.result.startTestRun()73 def test_stopTest(self):74 self.result.stopTest(self)75 def test_stopTestRun(self):76 self.result.stopTestRun()77 def test_addError(self):78 self.result.addError(self, subunit.RemoteError())79 def test_addError_details(self):80 self.result.addError(self, details={})81 def test_addFailure(self):82 self.result.addFailure(self, subunit.RemoteError())83 def test_addFailure_details(self):84 self.result.addFailure(self, details={})85 def test_addSuccess(self):86 self.result.addSuccess(self)87 def test_addSuccess_details(self):88 self.result.addSuccess(self, details={})89 def test_addSkip(self):90 self.result.addSkip(self, "foo")91 def test_addSkip_details(self):92 self.result.addSkip(self, details={})93 def test_addExpectedFailure(self):94 self.result.addExpectedFailure(self, subunit.RemoteError())95 def test_addExpectedFailure_details(self):96 self.result.addExpectedFailure(self, details={})97 def test_addUnexpectedSuccess(self):98 self.result.addUnexpectedSuccess(self)99 def test_addUnexpectedSuccess_details(self):100 self.result.addUnexpectedSuccess(self, details={})101 def test_progress(self):102 self.result.progress(1, subunit.PROGRESS_SET)103 def test_wasSuccessful(self):104 self.result.wasSuccessful()105 def test_shouldStop(self):106 self.result.shouldStop107 def test_stop(self):108 self.result.stop()109 def test_time(self):110 self.result.time(None)111class TestAutoTimingTestResultDecorator(unittest.TestCase):112 def setUp(self):113 # And end to the chain which captures time events.114 terminal = TimeCapturingResult()115 # The result object under test.116 self.result = subunit.test_results.AutoTimingTestResultDecorator(117 terminal)118 self.decorated = terminal119 def test_without_time_calls_time_is_called_and_not_None(self):120 self.result.startTest(self)121 self.assertEqual(1, len(self.decorated._calls))122 self.assertNotEqual(None, self.decorated._calls[0])123 def test_no_time_from_progress(self):124 self.result.progress(1, subunit.PROGRESS_CUR)125 self.assertEqual(0, len(self.decorated._calls))126 def test_no_time_from_shouldStop(self):127 self.decorated.stop()128 self.result.shouldStop129 self.assertEqual(0, len(self.decorated._calls))130 def test_calling_time_inhibits_automatic_time(self):131 # Calling time() outputs a time signal immediately and prevents132 # automatically adding one when other methods are called.133 time = datetime.datetime(2009,10,11,12,13,14,15, iso8601.Utc())134 self.result.time(time)135 self.result.startTest(self)136 self.result.stopTest(self)137 self.assertEqual(1, len(self.decorated._calls))138 self.assertEqual(time, self.decorated._calls[0])139 def test_calling_time_None_enables_automatic_time(self):140 time = datetime.datetime(2009,10,11,12,13,14,15, iso8601.Utc())141 self.result.time(time)142 self.assertEqual(1, len(self.decorated._calls))143 self.assertEqual(time, self.decorated._calls[0])144 # Calling None passes the None through, in case other results care.145 self.result.time(None)146 self.assertEqual(2, len(self.decorated._calls))147 self.assertEqual(None, self.decorated._calls[1])148 # Calling other methods doesn't generate an automatic time event.149 self.result.startTest(self)150 self.assertEqual(3, len(self.decorated._calls))151 self.assertNotEqual(None, self.decorated._calls[2])152 def test_set_failfast_True(self):153 self.assertFalse(self.decorated.failfast)154 self.result.failfast = True155 self.assertTrue(self.decorated.failfast)156class TestTagCollapsingDecorator(TestCase):157 def test_tags_collapsed_outside_of_tests(self):158 result = ExtendedTestResult()159 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)160 tag_collapser.tags(set(['a']), set())161 tag_collapser.tags(set(['b']), set())162 tag_collapser.startTest(self)163 self.assertEquals(164 [('tags', set(['a', 'b']), set([])),165 ('startTest', self),166 ], result._events)167 def test_tags_collapsed_outside_of_tests_are_flushed(self):168 result = ExtendedTestResult()169 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)170 tag_collapser.startTestRun()171 tag_collapser.tags(set(['a']), set())172 tag_collapser.tags(set(['b']), set())173 tag_collapser.startTest(self)174 tag_collapser.addSuccess(self)175 tag_collapser.stopTest(self)176 tag_collapser.stopTestRun()177 self.assertEquals(178 [('startTestRun',),179 ('tags', set(['a', 'b']), set([])),180 ('startTest', self),181 ('addSuccess', self),182 ('stopTest', self),183 ('stopTestRun',),184 ], result._events)185 def test_tags_forwarded_after_tests(self):186 test = subunit.RemotedTestCase('foo')187 result = ExtendedTestResult()188 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)189 tag_collapser.startTestRun()190 tag_collapser.startTest(test)191 tag_collapser.addSuccess(test)192 tag_collapser.stopTest(test)193 tag_collapser.tags(set(['a']), set(['b']))194 tag_collapser.stopTestRun()195 self.assertEqual(196 [('startTestRun',),197 ('startTest', test),198 ('addSuccess', test),199 ('stopTest', test),200 ('tags', set(['a']), set(['b'])),201 ('stopTestRun',),202 ],203 result._events)204 def test_tags_collapsed_inside_of_tests(self):205 result = ExtendedTestResult()206 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)207 test = subunit.RemotedTestCase('foo')208 tag_collapser.startTest(test)209 tag_collapser.tags(set(['a']), set())210 tag_collapser.tags(set(['b']), set(['a']))211 tag_collapser.tags(set(['c']), set())212 tag_collapser.stopTest(test)213 self.assertEquals(214 [('startTest', test),215 ('tags', set(['b', 'c']), set(['a'])),216 ('stopTest', test)],217 result._events)218 def test_tags_collapsed_inside_of_tests_different_ordering(self):219 result = ExtendedTestResult()220 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)221 test = subunit.RemotedTestCase('foo')222 tag_collapser.startTest(test)223 tag_collapser.tags(set(), set(['a']))224 tag_collapser.tags(set(['a', 'b']), set())225 tag_collapser.tags(set(['c']), set())226 tag_collapser.stopTest(test)227 self.assertEquals(228 [('startTest', test),229 ('tags', set(['a', 'b', 'c']), set()),230 ('stopTest', test)],231 result._events)232 def test_tags_sent_before_result(self):233 # Because addSuccess and friends tend to send subunit output234 # immediately, and because 'tags:' before a result line means235 # something different to 'tags:' after a result line, we need to be236 # sure that tags are emitted before 'addSuccess' (or whatever).237 result = ExtendedTestResult()238 tag_collapser = subunit.test_results.TagCollapsingDecorator(result)239 test = subunit.RemotedTestCase('foo')240 tag_collapser.startTest(test)241 tag_collapser.tags(set(['a']), set())242 tag_collapser.addSuccess(test)243 tag_collapser.stopTest(test)244 self.assertEquals(245 [('startTest', test),246 ('tags', set(['a']), set()),247 ('addSuccess', test),248 ('stopTest', test)],249 result._events)250class TestTimeCollapsingDecorator(TestCase):251 def make_time(self):252 # Heh heh.253 return datetime.datetime(254 2000, 1, self.getUniqueInteger(), tzinfo=iso8601.UTC)255 def test_initial_time_forwarded(self):256 # We always forward the first time event we see.257 result = ExtendedTestResult()258 tag_collapser = subunit.test_results.TimeCollapsingDecorator(result)259 a_time = self.make_time()260 tag_collapser.time(a_time)261 self.assertEquals([('time', a_time)], result._events)262 def test_time_collapsed_to_first_and_last(self):263 # If there are many consecutive time events, only the first and last264 # are sent through.265 result = ExtendedTestResult()266 tag_collapser = subunit.test_results.TimeCollapsingDecorator(result)267 times = [self.make_time() for i in range(5)]268 for a_time in times:269 tag_collapser.time(a_time)270 tag_collapser.startTest(subunit.RemotedTestCase('foo'))271 self.assertEquals(272 [('time', times[0]), ('time', times[-1])], result._events[:-1])273 def test_only_one_time_sent(self):274 # If we receive a single time event followed by a non-time event, we275 # send exactly one time event.276 result = ExtendedTestResult()277 tag_collapser = subunit.test_results.TimeCollapsingDecorator(result)278 a_time = self.make_time()279 tag_collapser.time(a_time)280 tag_collapser.startTest(subunit.RemotedTestCase('foo'))281 self.assertEquals([('time', a_time)], result._events[:-1])282 def test_duplicate_times_not_sent(self):283 # Many time events with the exact same time are collapsed into one284 # time event.285 result = ExtendedTestResult()286 tag_collapser = subunit.test_results.TimeCollapsingDecorator(result)287 a_time = self.make_time()288 for i in range(5):289 tag_collapser.time(a_time)290 tag_collapser.startTest(subunit.RemotedTestCase('foo'))291 self.assertEquals([('time', a_time)], result._events[:-1])292 def test_no_times_inserted(self):293 result = ExtendedTestResult()294 tag_collapser = subunit.test_results.TimeCollapsingDecorator(result)295 a_time = self.make_time()296 tag_collapser.time(a_time)297 foo = subunit.RemotedTestCase('foo')298 tag_collapser.startTest(foo)299 tag_collapser.addSuccess(foo)300 tag_collapser.stopTest(foo)301 self.assertEquals(302 [('time', a_time),303 ('startTest', foo),304 ('addSuccess', foo),305 ('stopTest', foo)], result._events)306class TestByTestResultTests(testtools.TestCase):307 def setUp(self):308 super(TestByTestResultTests, self).setUp()309 self.log = []310 self.result = subunit.test_results.TestByTestResult(self.on_test)311 if sys.version_info >= (3, 0):312 self.result._now = iter(range(5)).__next__313 else:314 self.result._now = iter(range(5)).next315 def assertCalled(self, **kwargs):316 defaults = {317 'test': self,318 'tags': set(),319 'details': None,320 'start_time': 0,321 'stop_time': 1,322 }323 defaults.update(kwargs)324 self.assertEqual([defaults], self.log)325 def on_test(self, **kwargs):326 self.log.append(kwargs)327 def test_no_tests_nothing_reported(self):328 self.result.startTestRun()329 self.result.stopTestRun()330 self.assertEqual([], self.log)331 def test_add_success(self):332 self.result.startTest(self)333 self.result.addSuccess(self)334 self.result.stopTest(self)335 self.assertCalled(status='success')336 def test_add_success_details(self):337 self.result.startTest(self)338 details = {'foo': 'bar'}339 self.result.addSuccess(self, details=details)340 self.result.stopTest(self)341 self.assertCalled(status='success', details=details)342 def test_tags(self):343 if not getattr(self.result, 'tags', None):344 self.skipTest("No tags in testtools")345 self.result.tags(['foo'], [])346 self.result.startTest(self)347 self.result.addSuccess(self)348 self.result.stopTest(self)349 self.assertCalled(status='success', tags=set(['foo']))350 def test_add_error(self):351 self.result.startTest(self)352 try:353 1/0354 except ZeroDivisionError:355 error = sys.exc_info()356 self.result.addError(self, error)357 self.result.stopTest(self)358 self.assertCalled(359 status='error',360 details={'traceback': TracebackContent(error, self)})361 def test_add_error_details(self):362 self.result.startTest(self)363 details = {"foo": text_content("bar")}364 self.result.addError(self, details=details)365 self.result.stopTest(self)366 self.assertCalled(status='error', details=details)367 def test_add_failure(self):368 self.result.startTest(self)369 try:370 self.fail("intentional failure")371 except self.failureException:372 failure = sys.exc_info()373 self.result.addFailure(self, failure)374 self.result.stopTest(self)375 self.assertCalled(376 status='failure',377 details={'traceback': TracebackContent(failure, self)})378 def test_add_failure_details(self):379 self.result.startTest(self)380 details = {"foo": text_content("bar")}381 self.result.addFailure(self, details=details)382 self.result.stopTest(self)383 self.assertCalled(status='failure', details=details)384 def test_add_xfail(self):385 self.result.startTest(self)386 try:387 1/0388 except ZeroDivisionError:389 error = sys.exc_info()390 self.result.addExpectedFailure(self, error)391 self.result.stopTest(self)392 self.assertCalled(393 status='xfail',394 details={'traceback': TracebackContent(error, self)})395 def test_add_xfail_details(self):396 self.result.startTest(self)397 details = {"foo": text_content("bar")}398 self.result.addExpectedFailure(self, details=details)399 self.result.stopTest(self)400 self.assertCalled(status='xfail', details=details)401 def test_add_unexpected_success(self):402 self.result.startTest(self)403 details = {'foo': 'bar'}404 self.result.addUnexpectedSuccess(self, details=details)405 self.result.stopTest(self)406 self.assertCalled(status='success', details=details)407 def test_add_skip_reason(self):408 self.result.startTest(self)409 reason = self.getUniqueString()410 self.result.addSkip(self, reason)411 self.result.stopTest(self)412 self.assertCalled(413 status='skip', details={'reason': text_content(reason)})414 def test_add_skip_details(self):415 self.result.startTest(self)416 details = {'foo': 'bar'}417 self.result.addSkip(self, details=details)418 self.result.stopTest(self)419 self.assertCalled(status='skip', details=details)420 def test_twice(self):421 self.result.startTest(self)422 self.result.addSuccess(self, details={'foo': 'bar'})423 self.result.stopTest(self)424 self.result.startTest(self)425 self.result.addSuccess(self)426 self.result.stopTest(self)427 self.assertEqual(428 [{'test': self,429 'status': 'success',430 'start_time': 0,431 'stop_time': 1,432 'tags': set(),433 'details': {'foo': 'bar'}},434 {'test': self,435 'status': 'success',436 'start_time': 2,437 'stop_time': 3,438 'tags': set(),439 'details': None},440 ],441 self.log)442class TestCsvResult(testtools.TestCase):443 def parse_stream(self, stream):444 stream.seek(0)445 reader = csv.reader(stream)446 return list(reader)447 def test_csv_output(self):448 stream = StringIO()449 result = subunit.test_results.CsvResult(stream)450 if sys.version_info >= (3, 0):451 result._now = iter(range(5)).__next__452 else:453 result._now = iter(range(5)).next454 result.startTestRun()455 result.startTest(self)456 result.addSuccess(self)457 result.stopTest(self)458 result.stopTestRun()459 self.assertEqual(460 [['test', 'status', 'start_time', 'stop_time'],461 [self.id(), 'success', '0', '1'],462 ],463 self.parse_stream(stream))464 def test_just_header_when_no_tests(self):465 stream = StringIO()466 result = subunit.test_results.CsvResult(stream)467 result.startTestRun()468 result.stopTestRun()469 self.assertEqual(470 [['test', 'status', 'start_time', 'stop_time']],471 self.parse_stream(stream))...

Full Screen

Full Screen

TestScript.py

Source:TestScript.py Github

copy

Full Screen

...43 @step Check that data values are as defined in CSV using testData.getValue(), testData.getIntValue(), testData.getDoubleValue(), testData.getDoubleWithPrecisionValue() and testData.getBooleanValue()44 @expected Check is successful45 """46 if testData.getValue('STRING_DATA') != 'string':47 testAPI.stopTest(Status.FAIL, "String data value doesn't match.")48 if testData.getIntValue('INT_DATA') != 2:49 testAPI.stopTest(Status.FAIL, "Integer data value doesn't match.")50 if testData.getDoubleValue('DOUBLE_DATA') != 3.3:51 testAPI.stopTest(Status.FAIL, "Double data value doesn't match.")52 if testData.getDoubleWithPrecisionValue('DOUBLE_WITH_PRECISION_DATA') != DoubleWithPrecision(5,0.1):53 testAPI.stopTest(Status.FAIL, "Double with precision data value doesn't match.")54 if testData.getBooleanValue('BOOLEAN_DATA') != True:55 testAPI.stopTest(Status.FAIL, "Boolean data value doesn't match.")56def Step3():57 """58 @step Modify data values and add a new one, using testData.setValue(), testData.setIntValue(), testData.setDoubleValue(), testData.setDoubleWithPrecisionValue() and testData.setBooleanValue()59 @expected None60 """61 testData.setValue('STRING_DATA', 'other')62 testData.setIntValue('INT_DATA', 5)63 testData.setDoubleValue('DOUBLE_DATA', 8.6)64 testData.setDoubleWithPrecisionValue('DOUBLE_WITH_PRECISION_DATA', DoubleWithPrecision(10,0.5))65 testData.setBooleanValue('BOOLEAN_DATA', False)66 testData.setValue('NEW_DATA', 'new')67def Step4():68 """69 @step Check that data values are as modified in step 3 using testData.getValue(), testData.getIntValue(), testData.getDoubleValue(), testData.getDoubleWithPrecisionValue() and testData.getBooleanValue()70 @expected Check is successful71 """72 if testData.getValue('STRING_DATA') != 'other':73 testAPI.stopTest(Status.FAIL, "String data value doesn't match.")74 if testData.getIntValue('INT_DATA') != 5:75 testAPI.stopTest(Status.FAIL, "Integer data value doesn't match.")76 if testData.getDoubleValue('DOUBLE_DATA') != 8.6:77 testAPI.stopTest(Status.FAIL, "Double data value doesn't match.")78 if testData.getDoubleWithPrecisionValue('DOUBLE_WITH_PRECISION_DATA') != DoubleWithPrecision(10,0.5):79 testAPI.stopTest(Status.FAIL, "Double with precision data value doesn't match.")80 if testData.getBooleanValue('BOOLEAN_DATA') != False:81 testAPI.stopTest(Status.FAIL, "Boolean data value doesn't match.")82 if testData.getValue('NEW_DATA') != 'new':83 testAPI.stopTest(Status.FAIL, "New data value doesn't match.")84def Step5():85 """86 @step Check that testData.contains() returns true for an existing test data and false for an inexistent test data87 @expected Check is successful88 """89 if not testData.contains('STRING_DATA'):90 testAPI.stopTest(Status.FAIL, "testData.contains('STRING_DATA') should return true")91 if testData.contains('INEXISTENT_DATA'):92 testAPI.stopTest(Status.FAIL, "testData.contains('INEXISTENT_DATA') should return false")93def Step6():94 """95 @step Check that after calling testData.remove(), test data doesn't contain the value anymore96 @expected Check is successful97 """98 testData.remove('STRING_DATA')99 if testData.contains('STRING_DATA'):100 testAPI.stopTest(Status.FAIL, "testData.remove() didn't remove the test data 'STRING_DATA'")101doStep(Step1)102doStep(Step2)103doStep(Step3)104doStep(Step4)105doStep(Step5)...

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