Best Python code snippet using stestr_python
test_deferred.py
Source:test_deferred.py
...17 return r, s18 def test_success(self):19 result, suite = self._loadSuite(detests.DeferredSetUpOK)20 suite(result)21 self.assertTrue(result.wasSuccessful())22 self.assertEqual(result.testsRun, 1)23 def test_fail(self):24 self.assertFalse(detests.DeferredSetUpFail.testCalled)25 result, suite = self._loadSuite(detests.DeferredSetUpFail)26 suite(result)27 self.assertFalse(result.wasSuccessful())28 self.assertEqual(result.testsRun, 1)29 self.assertEqual(len(result.failures), 0)30 self.assertEqual(len(result.errors), 1)31 self.assertFalse(detests.DeferredSetUpFail.testCalled)32 def test_callbackFail(self):33 self.assertFalse(detests.DeferredSetUpCallbackFail.testCalled)34 result, suite = self._loadSuite(detests.DeferredSetUpCallbackFail)35 suite(result)36 self.assertFalse(result.wasSuccessful())37 self.assertEqual(result.testsRun, 1)38 self.assertEqual(len(result.failures), 0)39 self.assertEqual(len(result.errors), 1)40 self.assertFalse(detests.DeferredSetUpCallbackFail.testCalled)41 def test_error(self):42 self.assertFalse(detests.DeferredSetUpError.testCalled)43 result, suite = self._loadSuite(detests.DeferredSetUpError)44 suite(result)45 self.assertFalse(result.wasSuccessful())46 self.assertEqual(result.testsRun, 1)47 self.assertEqual(len(result.failures), 0)48 self.assertEqual(len(result.errors), 1)49 self.assertFalse(detests.DeferredSetUpError.testCalled)50 def test_skip(self):51 self.assertFalse(detests.DeferredSetUpSkip.testCalled)52 result, suite = self._loadSuite(detests.DeferredSetUpSkip)53 suite(result)54 self.assertTrue(result.wasSuccessful())55 self.assertEqual(result.testsRun, 1)56 self.assertEqual(len(result.failures), 0)57 self.assertEqual(len(result.errors), 0)58 self.assertEqual(len(result.skips), 1)59 self.assertFalse(detests.DeferredSetUpSkip.testCalled)60class NeverFireTests(unittest.TestCase):61 def setUp(self):62 self._oldTimeout = util.DEFAULT_TIMEOUT_DURATION63 util.DEFAULT_TIMEOUT_DURATION = 0.164 def tearDown(self):65 util.DEFAULT_TIMEOUT_DURATION = self._oldTimeout66 def _loadSuite(self, klass):67 loader = pyunit.TestLoader()68 r = reporter.TestResult()69 s = loader.loadTestsFromTestCase(klass)70 return r, s71 def test_setUp(self):72 self.assertFalse(detests.DeferredSetUpNeverFire.testCalled)73 result, suite = self._loadSuite(detests.DeferredSetUpNeverFire)74 suite(result)75 self.assertFalse(result.wasSuccessful())76 self.assertEqual(result.testsRun, 1)77 self.assertEqual(len(result.failures), 0)78 self.assertEqual(len(result.errors), 1)79 self.assertFalse(detests.DeferredSetUpNeverFire.testCalled)80 self.assertTrue(result.errors[0][1].check(defer.TimeoutError))81class TestTester(unittest.TestCase):82 def getTest(self, name):83 raise NotImplementedError("must override me")84 def runTest(self, name):85 result = reporter.TestResult()86 self.getTest(name).run(result)87 return result88class DeferredTests(TestTester):89 def getTest(self, name):90 return detests.DeferredTests(name)91 def test_pass(self):92 result = self.runTest('test_pass')93 self.assertTrue(result.wasSuccessful())94 self.assertEqual(result.testsRun, 1)95 def test_passGenerated(self):96 result = self.runTest('test_passGenerated')97 self.assertTrue(result.wasSuccessful())98 self.assertEqual(result.testsRun, 1)99 self.assertTrue(detests.DeferredTests.touched)100 test_passGenerated.supress = [util.suppress(101 message="twisted.internet.defer.deferredGenerator is deprecated")]102 def test_passInlineCallbacks(self):103 """104 The body of a L{defer.inlineCallbacks} decorated test gets run.105 """106 result = self.runTest('test_passInlineCallbacks')107 self.assertTrue(result.wasSuccessful())108 self.assertEqual(result.testsRun, 1)109 self.assertTrue(detests.DeferredTests.touched)110 def test_fail(self):111 result = self.runTest('test_fail')112 self.assertFalse(result.wasSuccessful())113 self.assertEqual(result.testsRun, 1)114 self.assertEqual(len(result.failures), 1)115 def test_failureInCallback(self):116 result = self.runTest('test_failureInCallback')117 self.assertFalse(result.wasSuccessful())118 self.assertEqual(result.testsRun, 1)119 self.assertEqual(len(result.failures), 1)120 def test_errorInCallback(self):121 result = self.runTest('test_errorInCallback')122 self.assertFalse(result.wasSuccessful())123 self.assertEqual(result.testsRun, 1)124 self.assertEqual(len(result.errors), 1)125 def test_skip(self):126 result = self.runTest('test_skip')127 self.assertTrue(result.wasSuccessful())128 self.assertEqual(result.testsRun, 1)129 self.assertEqual(len(result.skips), 1)130 self.assertFalse(detests.DeferredTests.touched)131 def test_todo(self):132 result = self.runTest('test_expectedFailure')133 self.assertTrue(result.wasSuccessful())134 self.assertEqual(result.testsRun, 1)135 self.assertEqual(len(result.errors), 0)136 self.assertEqual(len(result.failures), 0)137 self.assertEqual(len(result.expectedFailures), 1)138 def test_thread(self):139 result = self.runTest('test_thread')140 self.assertEqual(result.testsRun, 1)141 self.assertTrue(result.wasSuccessful(), result.errors)142class TimeoutTests(TestTester):143 def getTest(self, name):144 return detests.TimeoutTests(name)145 def _wasTimeout(self, error):146 self.assertEqual(error.check(defer.TimeoutError),147 defer.TimeoutError)148 def test_pass(self):149 result = self.runTest('test_pass')150 self.assertTrue(result.wasSuccessful())151 self.assertEqual(result.testsRun, 1)152 def test_passDefault(self):153 result = self.runTest('test_passDefault')154 self.assertTrue(result.wasSuccessful())155 self.assertEqual(result.testsRun, 1)156 def test_timeout(self):157 result = self.runTest('test_timeout')158 self.assertFalse(result.wasSuccessful())159 self.assertEqual(result.testsRun, 1)160 self.assertEqual(len(result.errors), 1)161 self._wasTimeout(result.errors[0][1])162 def test_timeoutZero(self):163 result = self.runTest('test_timeoutZero')164 self.assertFalse(result.wasSuccessful())165 self.assertEqual(result.testsRun, 1)166 self.assertEqual(len(result.errors), 1)167 self._wasTimeout(result.errors[0][1])168 def test_skip(self):169 result = self.runTest('test_skip')170 self.assertTrue(result.wasSuccessful())171 self.assertEqual(result.testsRun, 1)172 self.assertEqual(len(result.skips), 1)173 def test_todo(self):174 result = self.runTest('test_expectedFailure')175 self.assertTrue(result.wasSuccessful())176 self.assertEqual(result.testsRun, 1)177 self.assertEqual(len(result.expectedFailures), 1)178 self._wasTimeout(result.expectedFailures[0][1])179 def test_errorPropagation(self):180 result = self.runTest('test_errorPropagation')181 self.assertFalse(result.wasSuccessful())182 self.assertEqual(result.testsRun, 1)183 self._wasTimeout(detests.TimeoutTests.timedOut)184 def test_classTimeout(self):185 loader = pyunit.TestLoader()186 suite = loader.loadTestsFromTestCase(detests.TestClassTimeoutAttribute)187 result = reporter.TestResult()188 suite.run(result)189 self.assertEqual(len(result.errors), 1)190 self._wasTimeout(result.errors[0][1])191 def test_callbackReturnsNonCallingDeferred(self):192 #hacky timeout193 # raises KeyboardInterrupt because Trial sucks194 from twisted.internet import reactor195 call = reactor.callLater(2, reactor.crash)196 result = self.runTest('test_calledButNeverCallback')197 if call.active():198 call.cancel()199 self.assertFalse(result.wasSuccessful())200 self._wasTimeout(result.errors[0][1])201# The test loader erroneously attempts to run this:...
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!!