Example #1
0
 def _log_test_failure(self, test_callable_name, err, message):
     """
     Add messaging about a test failure to the stream, which will be
     printed by the plugin's report method.
     """
     formatted_exception_info = ''.join(format_exception(*err)).replace('\n', '\n\t').rstrip()
     self._stream.writelines([
         ensure_unicode_string(test_callable_name),
         ensure_unicode_string(message),
         ensure_unicode_string(formatted_exception_info),
         '\n',
     ])
 def _log_test_failure(self, test_callable_name, err, message):
     """
     Add messaging about a test failure to the stream, which will be
     printed by the plugin's report method.
     """
     formatted_exception_info = ''.join(format_exception(*err)).replace('\n', '\n\t').rstrip()
     self._stream.writelines([
         ensure_unicode_string(test_callable_name),
         ensure_unicode_string(message),
         ensure_unicode_string(formatted_exception_info),
         '\n',
     ])
Example #3
0
 def _log_test_failure(self, test_callable_name, err, message):
     """
     Add messaging about a test failure to the stream, which will be
     printed by the plugin's report method.
     """
     self._stream.writelines([
         ensure_unicode_string(test_callable_name),
         message,
         '\n\t',
         ensure_unicode_string(err[0]),
         '\n\t',
         ensure_unicode_string(err[1]),
         '\n\t',
         ensure_unicode_string(err[2]),
         '\n',
     ])
Example #4
0
 def _log_test_failure(self, test_callable_name, err, message):
     """
     Add messaging about a test failure to the stream, which will be
     printed by the plugin's report method.
     """
     self._stream.writelines([
         ensure_unicode_string(test_callable_name),
         message,
         '\n\t',
         ensure_unicode_string(err[0]),
         '\n\t',
         ensure_unicode_string(err[1]),
         '\n\t',
         ensure_unicode_string(err[2]),
         '\n',
     ])
Example #5
0
    def test_ensure_unicode_string_handles_nonascii_exception_message(self):
        message = u'\u2013'
        encoded_message = message.encode('utf-8')
        ex = Exception(encoded_message)

        string = ensure_unicode_string(ex)
        if sys.version_info >= (3, ):
            message = unicode_type(encoded_message)
        self.assertEqual(string, message)
Example #6
0
    def test_ensure_unicode_string_handles_nonascii_exception_message(self):
        message = u'\u2013'
        encoded_message = message.encode('utf-8')
        ex = Exception(encoded_message)

        string = ensure_unicode_string(ex)
        if sys.version_info >= (3,):
            message = unicode_type(encoded_message)
        self.assertEqual(string, message)
Example #7
0
 def test_ensure_unicode_string_handles_various_strings(
     self,
     string,
     expected_unicode_string,
 ):
     unicode_string = ensure_unicode_string(string)
     if sys.version_info >= (3, ):
         expected_unicode_string = unicode_type(string)
     self.assertTrue(isinstance(unicode_string, unicode_type))
     self.assertTrue(expected_unicode_string in unicode_string)
Example #8
0
 def test_ensure_unicode_string_handles_various_strings(
         self,
         string,
         expected_unicode_string,
 ):
     unicode_string = ensure_unicode_string(string)
     if sys.version_info >= (3,):
         expected_unicode_string = unicode_type(string)
     self.assertTrue(isinstance(unicode_string, unicode_type))
     self.assertTrue(expected_unicode_string in unicode_string)
Example #9
0
 def test_ensure_unicode_string_handles_various_strings(
         self,
         string,
         expected_unicode_string,
 ):
     unicode_string = ensure_unicode_string(string)
     if sys.version_info.major >= 3:
         expected_unicode_string = unicode_type(string)
     self.assertIsInstance(unicode_string, unicode_type)
     self.assertIn(expected_unicode_string, unicode_string)
Example #10
0
 def test_ensure_unicode_string_handles_various_strings(
     self,
     string,
     expected_unicode_string,
 ):
     unicode_string = ensure_unicode_string(string)
     if sys.version_info.major >= 3:
         expected_unicode_string = unicode_type(string)
     self.assertIsInstance(unicode_string, unicode_type)
     self.assertIn(expected_unicode_string, unicode_string)
    def _handle_test_success(self, test):
        """
        Handle a flaky test success.
        Count remaining retries and compare with number of required successes
        that have not yet been achieved; retry if necessary.

        Returning True from this method keeps the test runner from reporting
        the test as a success; this way we can retry and only report as a
        success if the test has passed the required number of times.

        :param test:
            The test that has raised an error
        :type test:
            :class:`nose.case.Test` or :class:`Function`
        :return:
            True, if the test will be rerun; False, if the test runner should handle it.
        :rtype:
            `bool`
        """
        try:
            name = self._get_test_callable_name(test)
        except AttributeError:
            return False
        need_reruns = self._should_handle_test_success(test)

        if self._has_flaky_attributes(test):
            self._had_flaky_tests = True
            flaky = self._get_flaky_attributes(test)
            min_passes = flaky[FlakyNames.MIN_PASSES]
            passes = flaky[FlakyNames.CURRENT_PASSES] + 1
            self._set_flaky_attribute(test, FlakyNames.CURRENT_PASSES, passes)
            self._increment_flaky_attribute(test, FlakyNames.CURRENT_RUNS)

            if self._flaky_success_report:
                self._stream.writelines([
                    ensure_unicode_string(name),
                    ' passed {} out of the required {} times. '.format(
                        passes,
                        min_passes,
                    ),
                ])
                if need_reruns:
                    self._stream.write(
                        'Running test again until it passes {} times.\n'.format(
                            min_passes,
                        )
                    )
                else:
                    self._stream.write('Success!\n')

        if need_reruns:
            self._mark_test_for_rerun(test)
        return need_reruns
Example #12
0
    def _handle_test_success(self, test):
        """
        Handle a flaky test success.
        Count remaining retries and compare with number of required successes
        that have not yet been achieved; retry if necessary.

        Returning True from this method keeps the test runner from reporting
        the test as a success; this way we can retry and only report as a
        success if the test has passed the required number of times.

        :param test:
            The test that has raised an error
        :type test:
            :class:`nose.case.Test` or :class:`Function`
        :return:
            True, if the test will be rerun; False, if the test runner should handle it.
        :rtype:
            `bool`
        """
        try:
            name = self._get_test_callable_name(test)
        except AttributeError:
            return False
        need_reruns = self._should_handle_test_success(test)

        if self._has_flaky_attributes(test):
            flaky = self._get_flaky_attributes(test)
            min_passes = flaky[FlakyNames.MIN_PASSES]
            passes = flaky[FlakyNames.CURRENT_PASSES] + 1
            self._set_flaky_attribute(test, FlakyNames.CURRENT_PASSES, passes)
            self._increment_flaky_attribute(test, FlakyNames.CURRENT_RUNS)

            if self._flaky_success_report:
                self._stream.writelines([
                    ensure_unicode_string(name),
                    ' passed {0} out of the required {1} times. '.format(
                        passes,
                        min_passes,
                    ),
                ])
                if need_reruns:
                    self._stream.write(
                        'Running test again until it passes {0} times.\n'.format(
                            min_passes,
                        )
                    )
                else:
                    self._stream.write('Success!\n')

        if need_reruns:
            self._mark_test_for_rerun(test)
        return need_reruns
Example #13
0
    def _handle_test_success(self, test):
        """
        Handle a flaky test success.
        Count remaining retries and compare with number of required successes
        that have not yet been achieved; retry if necessary.

        Returning True from this method keeps the test runner from reporting
        the test as a success; this way we can retry and only report as a
        success if the test has passed the required number of times.
        :param test:
            The test that has raised an error
        :type test:
            :class:`nose.case.Test`
        :return:
            True, if the test will be rerun; False, if nose should handle it.
        :rtype:
            `bool`
        """
        test_callable, test_callable_name = self._get_test_callable_and_name(
            test, )
        current_runs = self._get_flaky_attribute(test_callable,
                                                 FlakyNames.CURRENT_RUNS)
        if current_runs is None:
            return False
        current_runs += 1
        current_passes = self._get_flaky_attribute(test_callable,
                                                   FlakyNames.CURRENT_PASSES)
        current_passes += 1
        self._set_flaky_attribute(test_callable, FlakyNames.CURRENT_RUNS,
                                  current_runs)
        self._set_flaky_attribute(test_callable, FlakyNames.CURRENT_PASSES,
                                  current_passes)
        flaky = self._get_flaky_attributes(test_callable)
        min_passes = flaky[FlakyNames.MIN_PASSES]
        self._stream.writelines([
            ensure_unicode_string(test_callable_name),
            ' passed {0} out of the required {1} times. '.format(
                current_passes,
                min_passes,
            ),
        ])
        if not self._has_flaky_test_succeeded(flaky):
            self._stream.write(
                'Running test again until it passes {0} times.\n'.format(
                    min_passes, ))
            self._rerun_test(test)
            return True
        else:
            self._stream.write('Success!\n')
            return False
Example #14
0
    def _handle_test_success(self, test):
        """
        Handle a flaky test success.
        Count remaining retries and compare with number of required successes
        that have not yet been achieved; retry if necessary.

        Returning True from this method keeps the test runner from reporting
        the test as a success; this way we can retry and only report as a
        success if the test has passed the required number of times.
        :param test:
            The test that has raised an error
        :type test:
            :class:`nose.case.Test`
        :return:
            True, if the test will be rerun; False, if nose should handle it.
        :rtype:
            `bool`
        """
        _, _, name = self._get_test_declaration_callable_and_name(test)
        current_runs = self._get_flaky_attribute(
            test,
            FlakyNames.CURRENT_RUNS
        )
        if current_runs is None:
            return False
        current_runs += 1
        current_passes = self._get_flaky_attribute(
            test,
            FlakyNames.CURRENT_PASSES
        )
        current_passes += 1
        self._set_flaky_attribute(
            test,
            FlakyNames.CURRENT_RUNS,
            current_runs
        )
        self._set_flaky_attribute(
            test,
            FlakyNames.CURRENT_PASSES,
            current_passes
        )
        flaky = self._get_flaky_attributes(test)
        min_passes = flaky[FlakyNames.MIN_PASSES]
        self._stream.writelines([
            ensure_unicode_string(name),
            ' passed {0} out of the required {1} times. '.format(
                current_passes,
                min_passes,
            ),
        ])
        if not self._has_flaky_test_succeeded(flaky):
            self._stream.write(
                'Running test again until it passes {0} times.\n'.format(
                    min_passes,
                )
            )
            self._rerun_test(test)
            return True
        else:
            self._stream.write('Success!\n')
            return False