Exemple #1
0
    def test_finally_failure_blocks(self):
        """Validate behavior of blocks after FINALLY block failure.

        We check that other blocks don't run after a finally's failure.
        """
        MockFlow.blocks = (SuccessBlock.params(mode=MODE_CRITICAL),
                           FailureBlock.params(mode=MODE_FINALLY),
                           SuccessBlock.params(mode=MODE_CRITICAL),
                           SuccessBlock.params(mode=MODE_OPTIONAL))

        test_flow = MockFlow()
        self.run_test(test_flow)

        self.assertFalse(self.result.wasSuccessful(),
                         'Flow succeeded when it should have failed')

        self.assertEqual(self.result.testsRun, 1,
                         "Result didn't run the correct number of tests")

        self.assertEqual(len(self.result.failures), 1,
                         "Result didn't fail the correct number of tests")

        self.validate_blocks(test_flow, successes=1, failures=1, skips=2)

        # === Validate data object ===
        self.assertFalse(test_flow.data.success,
                         'Flow data result should have been False')

        self.assertEqual(test_flow.data.exception_type, TestOutcome.FAILED,
                         'Flow data status should have been failure')
Exemple #2
0
    def test_optional_blocks(self):
        """Validate behavior of block in OPTIONAL mode.

        We check that other blocks run after a optional's failure but don't
        after an error in an optional block.
        """
        MockFlow.blocks = (SuccessBlock.params(mode=MODE_CRITICAL),
                           FailureBlock.params(mode=MODE_OPTIONAL),
                           SuccessBlock.params(mode=MODE_CRITICAL),
                           ErrorBlock.params(mode=MODE_OPTIONAL),
                           SuccessBlock.params(mode=MODE_CRITICAL))

        test_flow = MockFlow()
        self.run_test(test_flow)

        self.assertFalse(self.result.wasSuccessful(),
                         'Flow succeeded when it should have failed')

        self.assertEqual(self.result.testsRun, 1,
                         "Result didn't run the correct number of tests")

        self.assertEqual(len(self.result.errors), 1,
                         "Result didn't had the correct number of errors")

        self.validate_blocks(test_flow, successes=2, failures=1, errors=1,
                             skips=1)

        # === Validate data object ===
        self.assertFalse(test_flow.data.success,
                         'Flow data result should have been False')

        self.assertEqual(test_flow.data.exception_type, TestOutcome.ERROR,
                         'Flow data status should have been error')