def _fill_case(self, report, call, pyteststatus, status):
        """
        Finalizes with important data
        :param report: py.test's `TestReport`
        :param call: py.test's `CallInfo`
        :param pyteststatus: the failed/xfailed/xpassed thing
        :param status: a :py:class:`allure.constants.Status` entry
        """
        [
            self.attach(name, contents, AttachmentType.TEXT)
            for (name, contents) in dict(report.sections).items()
        ]

        self.test.stop = now()
        self.test.status = status

        if status in FAILED_STATUSES:
            self.test.failure = Failure(
                message=get_exception_message(call.excinfo, pyteststatus,
                                              report),
                trace=report.longrepr
                or hasattr(report, 'wasxfail') and report.wasxfail)
        elif status in SKIPPED_STATUSES:
            skip_message = type(
                report.longrepr
            ) == tuple and report.longrepr[2] or report.wasxfail
            trim_msg_len = 89
            short_message = skip_message.split('\n')[0][:trim_msg_len]

            # FIXME: see pytest.runner.pytest_runtest_makereport
            self.test.failure = Failure(
                message=(short_message + '...' *
                         (len(skip_message) > trim_msg_len)),
                trace=status == Status.PENDING and report.longrepr
                or short_message != skip_message and skip_message or '')
    def end_suitesetup(self, name, attributes):

        end_test_attributes = {
            'critical': 'yes',
            'doc': 'Test Suite Setup section',
            'starttime': attributes['starttime'],
            'endtime': attributes['endtime'],
            'status': 'PASS',
            'tags': [],
            'id': 's1-s1-t0',
            'longname': BuiltIn().get_variable_value('${SUITE_NAME}'),
            'template': ''
        }

        test = self.stack.pop()
        BuiltIn().run_keyword(name)

        if end_test_attributes.get('status') == Robot.PASS:
            test.status = Status.PASSED
        elif end_test_attributes.get('status') == Robot.FAIL:
            test.status = Status.FAILED
            test.failure = Failure(message=end_test_attributes.get('message'),
                                   trace='')
        elif end_test_attributes.get('doc') is not '':
            test.description = attributes.get('doc')

        if end_test_attributes['tags']:
            for tag in end_test_attributes['tags']:
                if re.search(self.AllureIssueIdRegEx, tag):
                    test.labels.append(TestLabel(name=Label.ISSUE, value=tag))
                if tag.startswith('feature'):
                    test.labels.append(
                        TestLabel(name='feature', value=tag.split(':')[-1]))
                if tag.startswith('story'):
                    test.labels.append(
                        TestLabel(name='story', value=tag.split(':')[-1]))
                elif tag in SEVERITIES:
                    test.labels.append(TestLabel(name='severity', value=tag))
                elif tag in STATUSSES:
                    test.status = tag  # overwrites the actual test status with this value.

        self.PabotPoolId = BuiltIn().get_variable_value(
            '${PABOTEXECUTIONPOOLID}')

        if (self.PabotPoolId is not None):
            self.threadId = 'PabotPoolId-' + str(self.PabotPoolId)
        else:
            self.threadId = threading._get_ident()

        test.labels.append(TestLabel(name='thread', value=str(self.threadId)))

        self.testsuite.tests.append(test)
        test.stop = now()
        return test
    def end_test(self, name, attributes):
#         logger.console('\nend_test: ['+name+']')
#         logger.console(attributes)
#         logger.console('   [stack lenght] ['+str(len(self.stack))+'] [testsuite lenght] ['+ str(len(self.testsuite.tests))+']')

        test = self.stack.pop()
        
        if attributes.get('status') == Robot.PASS:
            test.status = Status.PASSED
        elif attributes.get('status')==Robot.FAIL:
            test.status = Status.FAILED
            test.failure = Failure(message=attributes.get('message'), trace='')
        elif attributes.get('doc') is not '':
            test.description = attributes.get('doc')

        if attributes['tags']:
            for tag in attributes['tags']:
                if re.search(self.AllureIssueIdRegEx, tag):
                    test.labels.append(TestLabel(
                        name=Label.ISSUE,
                        value=tag))
                elif tag.startswith('feature'):
                    test.labels.append(TestLabel(
                        name='feature',
                        value=tag.split(':')[-1]))
                elif tag.startswith('story'):
                    test.labels.append(TestLabel(
                        name='story',
                        value=tag.split(':')[-1]))
                elif tag in SEVERITIES:
                    test.labels.append(TestLabel(
                        name='severity',
                        value=tag))                    
                    test.severity = tag
                elif tag in STATUSSES:
                    test.status = tag  # overwrites the actual test status with this value.
                else:
                    test.labels.append(TestLabel(
                        name='tag',
                        value=tag))

        self.PabotPoolId =  BuiltIn().get_variable_value('${PABOTEXECUTIONPOOLID}')
        if(self.PabotPoolId is not None):
            self.threadId = 'PabotPoolId-' + str(self.PabotPoolId)
        else:
            self.threadId = threading._get_ident()
                
        test.labels.append(TestLabel(
            name='thread',
            value=str(self.threadId)))

        self.testsuite.tests.append(test)
        test.stop = now()        
        return test
    def _fill_case(self, report, call, pyteststatus, status):
        """
        Finalizes with important data
        :param report: py.test's `TestReport`
        :param call: py.test's `CallInfo`
        :param pyteststatus: the failed/xfailed/xpassed thing
        :param status: a :py:class:`allure.constants.Status` entry
        """
        # To enable color coding in stdout log we have to write allure attachments as html.
        for (name, contents) in dict(report.sections).items():
            if "stdout" in name:
                attachment_type = AttachmentType.HTML
                formatted_contents = self._convert_to_html(contents)
            else:
                attachment_type = AttachmentType.TEXT
                formatted_contents = contents
            self.attach(name, formatted_contents, attachment_type)

        self.test.stop = now()
        self.test.status = status

        if status in FAILED_STATUSES:
            self.test.failure = Failure(message=get_exception_message(
                call.excinfo, pyteststatus, report),
                                        trace=report.longrepr)
        elif status in SKIPPED_STATUSES:
            skip_message = isinstance(
                report.longrepr,
                tuple) and report.longrepr[2] or report.wasxfail
            trim_msg_len = 89
            short_message = skip_message.split('\n')[0][:trim_msg_len]

            # FIXME: see pytest.runner.pytest_runtest_makereport
            self.test.failure = Failure(
                message=(short_message + '...' *
                         (len(skip_message) > trim_msg_len)),
                trace=status == Status.PENDING and report.longrepr
                or short_message != skip_message and skip_message or '')
Exemple #5
0
    def stop_case(self, status, message=None, trace=None):
        """
        :arg status: one of :py:class:`allure.constants.Status`
        :arg message: error message from the test
        :arg trace: error trace from the test

        Finalizes with important data the test at the top of ``self.stack`` and returns it

        If either ``message`` or ``trace`` are given adds a ``Failure`` object to the test with them.
        """
        test = self.stack[-1]
        test.status = status
        test.stop = now()

        if message or trace:
            test.failure = Failure(message=message, trace=trace)

        self.testsuite.tests.append(test)

        return test