Esempio n. 1
0
    def pytest_runtest_setup(self, item):
        if not self._cache.get(item.nodeid):
            uuid = self._cache.push(item.nodeid)
            test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
            self.allure_logger.schedule_test(uuid, test_result)

        yield

        uuid = self._cache.get(item.nodeid)
        test_result = self.allure_logger.get_test(uuid)
        for fixturedef in _test_fixtures(item):
            group_uuid = self._cache.get(fixturedef)
            if not group_uuid:
                group_uuid = self._cache.push(fixturedef)
                group = TestResultContainer(uuid=group_uuid)
                self.allure_logger.start_group(group_uuid, group)
            self.allure_logger.update_group(group_uuid, children=uuid)
        params = item.callspec.params if hasattr(item, 'callspec') else {}

        test_result.name = allure_name(item, params)
        test_result.description = allure_description(item)
        test_result.descriptionHtml = allure_description_html(item)
        test_result.fullName = allure_full_name(item)
        test_result.historyId = md5(test_result.fullName)
        test_result.parameters.extend(
            [Parameter(name=name, value=represent(value)) for name, value in params.items()])
Esempio n. 2
0
    def pytest_fixture_setup(self, fixturedef, request):
        fixture_name = fixturedef.argname

        container_uuid = self._cache.get(fixturedef)

        if not container_uuid:
            container_uuid = self._cache.push(fixturedef)
            container = TestResultContainer(uuid=container_uuid)
            self.allure_logger.start_group(container_uuid, container)

        self.allure_logger.update_group(container_uuid, start=now())

        before_fixture_uuid = uuid4()
        before_fixture = TestBeforeResult(name=fixture_name, start=now())
        self.allure_logger.start_before_fixture(container_uuid, before_fixture_uuid, before_fixture)

        outcome = yield

        self.allure_logger.stop_before_fixture(before_fixture_uuid,
                                               stop=now(),
                                               status=get_outcome_status(outcome),
                                               statusDetails=get_outcome_status_details(outcome))

        finalizers = getattr(fixturedef, '_finalizers', [])
        for index, finalizer in enumerate(finalizers):
            name = '{fixture}::{finalizer}'.format(fixture=fixturedef.argname,
                                                   finalizer=getattr(finalizer, "__name__", index))
            finalizers[index] = allure_commons.fixture(finalizer, parent_uuid=container_uuid, name=name)
Esempio n. 3
0
 def pytest_runtest_call(self, item):
     uuid = self._cache.get(item.nodeid)
     test_result = self.allure_logger.get_test(uuid)
     if test_result:
         test_result.start = now()
     yield
     if test_result:
         test_result.stop = now()
Esempio n. 4
0
 def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
     if name in FIXTURES:
         self.logger.stop_before_fixture(uuid=uuid,
                                         stop=now(),
                                         status=get_status(exc_val),
                                         statusDetails=get_status_details(
                                             exc_type, exc_val, exc_tb))
    def stop_current_test(self, name, attributes):
        uuid = self.stack.pop()
        test = self.reporter.get_test(uuid)
        test.status = utils.get_allure_status(attributes.get('status'))
        test.labels.extend(utils.get_allure_suites(attributes.get('longname')))

        test.labels.extend(allure_tags(attributes))
        for label_type in (LabelType.EPIC, LabelType.FEATURE, LabelType.STORY):
            test.labels.extend(allure_labels(attributes, label_type))
        for link_type in (LinkType.ISSUE, LinkType.TEST_CASE, LinkType.LINK):
            test.links.extend(allure_links(attributes, link_type))
        test.labels.append(Label(name=LabelType.THREAD, value=self.pool_id))
        test.labels.append(Label(name=LabelType.HOST, value=host_tag()))
        test.labels.append(
            Label(name=LabelType.FRAMEWORK, value='robotframework'))
        test.labels.append(
            Label(name=LabelType.LANGUAGE, value=platform_label()))
        test.statusDetails = StatusDetails(message=attributes.get('message'),
                                           trace=self.get_traceback_message())
        test.description = attributes.get('doc')
        last_link = list(self.links.values())[-1] if self.links else None
        if attributes.get(Severity.CRITICAL, 'no') == 'yes':
            test.labels.append(
                Label(name=LabelType.SEVERITY, value=Severity.CRITICAL))
        if last_link:
            test.links.append(Link(LinkType.LINK, last_link, 'Link'))
        test.stop = now()
        self.reporter.close_test(uuid)
Esempio n. 6
0
    def done(self, status: Status, job_log=None):
        if self.reporter is None:
            return

        self.test_case.status = status

        self.test_case.labels.append(
            Label(name=LabelType.FRAMEWORK, value=self.job.tool))
        self.test_case.labels.append(
            Label(name=LabelType.HOST, value=socket.gethostname()))
        self.test_case.parameters.append(
            Parameter(name="TOOL", value=self.job.tool))

        for l in self.job.labels:
            self.test_case.labels.append(Label(name=l[0], value=l[1]))
        for p in self.job.parameters:
            self.test_case.parameters.append(Parameter(name=p[0], value=p[1]))

        # Record the run variables as test parameters
        for k, v in self.job.runvars.items():
            self.test_case.parameters.append(Parameter(name=k, value=v))

        # Record the seed as a test parameter
        self.test_case.parameters.append(
            Parameter(name="SEED", value=str(self.job.seed)))

        if job_log is not None:
            self.reporter.attach_file(uuid4(), job_log, "job.log")
        for a in self.job.attachments:
            pass

        self.test_case.stop = now()
        self.reporter.close_test(self.test_uuid)

        pass
 def start_new_keyword(self, name, attributes):
     uuid = uuid4()
     parent_uuid = self.stack[-1]
     step_name = '{} = {}'.format(attributes.get('assign')[0], name) if attributes.get('assign') else name
     args = {
         'name': step_name,
         'description': attributes.get('doc'),
         'parameters': utils.get_allure_parameters(attributes.get('args')),
         'start': now()
     }
     keyword_type = attributes.get('type')
     last_item = self.reporter.get_last_item()
     if keyword_type in RobotKeywordType.FIXTURES and not isinstance(last_item, TestStepResult):
         if isinstance(last_item, TestResult):
             parent_uuid = self.stack[-2]
         if keyword_type == RobotKeywordType.SETUP:
             self.reporter.start_before_fixture(parent_uuid, uuid, TestBeforeResult(**args))
         elif keyword_type == RobotKeywordType.TEARDOWN:
             self.reporter.start_after_fixture(parent_uuid, uuid, TestAfterResult(**args))
         self.stack.append(uuid)
         return
     self.stack.append(uuid)
     self.reporter.start_step(parent_uuid=parent_uuid,
                              uuid=uuid,
                              step=TestStepResult(**args))
 def end_current_keyword(self, name, attributes):
     uuid = self.stack.pop()
     if uuid in self.items_log:
         keyword_logs = self.items_log.pop(uuid)
         if len(keyword_logs) < self.MAX_STEP_MESSAGE_COUNT:
             self.create_message_steps(uuid, *keyword_logs)
         else:
             self.reporter.attach_data(
                 uuid=uuid4(),
                 body=self.format_keyword_logs_to_attachment(*keyword_logs),
                 name='Keyword Log',
                 attachment_type=AttachmentType.HTML)
     args = {
         'uuid': uuid,
         'status': utils.get_allure_status(attributes.get('status')),
         'stop': now()
     }
     keyword_type = attributes.get('type')
     parent_item = self.reporter.get_last_item()
     if keyword_type in RobotKeywordType.FIXTURES and not isinstance(
             parent_item, TestStepResult):
         if keyword_type == RobotKeywordType.SETUP:
             self.reporter.stop_before_fixture(**args)
             return
         elif keyword_type == RobotKeywordType.TEARDOWN:
             self.reporter.stop_after_fixture(**args)
             return
     self.reporter.stop_step(**args)
Esempio n. 9
0
 def start_step(self, uuid, title, params):
     parameters = [
         Parameter(name=name, value=value)
         for name, value in params.items()
     ]
     step = TestStepResult(name=title, start=now(), parameters=parameters)
     self.allure_logger.start_step(None, uuid, step)
Esempio n. 10
0
 def stop_behave_step(self, result):
     status = step_status(result)
     status_details = step_status_details(result)
     self.logger.stop_step(self.current_step_uuid,
                           stop=now(),
                           status=status,
                           statusDetails=status_details)
Esempio n. 11
0
    def stop_scenario(self, scenario):
        should_run = (scenario.should_run_with_tags(self.behave_config.tags)
                      and scenario.should_run_with_name_select(
                          self.behave_config))
        should_drop_skipped_by_option = scenario.status == 'skipped' and not self.behave_config.show_skipped
        should_drop_excluded = self.hide_excluded and (
            scenario.skip_reason == TEST_PLAN_SKIP_REASON or not should_run)

        if should_drop_skipped_by_option or should_drop_excluded:
            self.logger.drop_test(self.current_scenario_uuid)
        else:
            status = scenario_status(scenario)
            status_details = scenario_status_details(scenario)

            self.flush_steps()
            test_result = self.logger.get_test(self.current_scenario_uuid)
            test_result.stop = now()
            test_result.status = status
            test_result.statusDetails = status_details
            self.logger.close_test(self.current_scenario_uuid)
            self.current_step_uuid = None
            self.group_context.append_test(self.current_scenario_uuid)
            self.group_context.exit()

        self.current_scenario_uuid = None
Esempio n. 12
0
    def start_test(self, parent_uuid, uuid, name, parameters, context):
        scenario = context['scenario']
        self.fixture_context.enter()
        self.execution_context.enter()
        self.execution_context.append(uuid)

        test_case = TestResult(uuid=uuid, start=now())
        test_case.name = scenario_name(scenario)
        test_case.historyId = scenario_history_id(scenario)
        test_case.description = '\n'.join(scenario.description)
        test_case.parameters = scenario_parameters(scenario)
        test_case.labels.extend([
            Label(name=LabelType.TAG, value=tag)
            for tag in scenario_tags(scenario)
        ])
        test_case.labels.append(
            Label(name=LabelType.SEVERITY,
                  value=scenario_severity(scenario).value))
        test_case.labels.append(
            Label(name=LabelType.FEATURE, value=scenario.feature.name))
        test_case.labels.append(Label(name=LabelType.FRAMEWORK,
                                      value='behave'))
        test_case.labels.append(
            Label(name=LabelType.LANGUAGE, value=platform_label()))

        self.logger.schedule_test(uuid, test_case)
Esempio n. 13
0
 def start_new_keyword(self, name, attributes):
     uuid = uuid4()
     parent_uuid = self.stack[-1]
     step_name = '{} = {}'.format(
         attributes.get('assign')[0],
         name) if attributes.get('assign') else name
     args = {
         'name': step_name,
         'description': attributes.get('doc'),
         'parameters': utils.get_allure_parameters(attributes.get('args')),
         'start': now()
     }
     keyword_type = attributes.get('type')
     last_item = self.reporter.get_last_item()
     if keyword_type in RobotKeywordType.FIXTURES and not isinstance(
             last_item, TestStepResult):
         if isinstance(last_item, TestResult):
             parent_uuid = self.stack[-2]
         if keyword_type == RobotKeywordType.SETUP:
             self.reporter.start_before_fixture(parent_uuid, uuid,
                                                TestBeforeResult(**args))
         elif keyword_type == RobotKeywordType.TEARDOWN:
             self.reporter.start_after_fixture(parent_uuid, uuid,
                                               TestAfterResult(**args))
         self.stack.append(uuid)
         return
     self.stack.append(uuid)
     self.reporter.start_step(parent_uuid=parent_uuid,
                              uuid=uuid,
                              step=TestStepResult(**args))
Esempio n. 14
0
 def start_step(self, parent_uuid=None, uuid=None):
     parent = self._get_item(uuid=parent_uuid, item_type=ExecutableItem)
     step = TestStepResult()
     step.start = now()
     parent.steps.append(step)
     self._items[uuid or uuid4()] = step
     yield step
Esempio n. 15
0
    def start_scenario(self, scenario):
        self.current_scenario_uuid = uuid4()
        self.fixture_context.enter()
        self.execution_context.enter()
        self.execution_context.append(self.current_scenario_uuid)

        test_case = TestResult(uuid=self.current_scenario_uuid, start=now())
        test_case.name = scenario_name(scenario)
        test_case.fullName = get_fullname(scenario)
        test_case.historyId = scenario_history_id(scenario)
        test_case.description = '\n'.join(scenario.description)
        test_case.parameters = scenario_parameters(scenario)

        issue_pattern = self.behave_config.userdata.get(
            'AllureFormatter.issue_pattern', None)
        link_pattern = self.behave_config.userdata.get(
            'AllureFormatter.link_pattern', None)
        test_case.links.extend(
            scenario_links(scenario,
                           issue_pattern=issue_pattern,
                           link_pattern=link_pattern))
        test_case.labels.extend(scenario_labels(scenario))
        test_case.labels.append(
            Label(name=LabelType.FEATURE, value=scenario.feature.name))
        test_case.labels.append(Label(name=LabelType.FRAMEWORK,
                                      value='behave'))
        test_case.labels.append(
            Label(name=LabelType.LANGUAGE, value=platform_label()))

        self.logger.schedule_test(self.current_scenario_uuid, test_case)
Esempio n. 16
0
 def start_step(self, uuid, title, params):
     """start step"""
     step_data = StepData()
     self._cache.push(step_data, uuid)
     parameters = [Parameter(name=name, value=value) for name, value in params.items()]
     step = TestStepResult(name=title, start=now(), parameters=parameters)
     self.allure_logger.start_step(None, uuid, step)
Esempio n. 17
0
    def before_scenario(self, _, scenario):
        uuid = scenario_history_id(scenario)

        test_case = TestResult(uuid=uuid, start=now())
        test_case.name = scenario_name(scenario)
        test_case.historyId = scenario_history_id(scenario)

        self.allure_lifecycle.schedule_test(uuid, test_case)
Esempio n. 18
0
 def start_step(self, uuid, title, params):
     with self.lifecycle.start_step() as step:
         step.name = title
         step.start = now()
         step.parameters = [
             Parameter(name=name, value=value)
             for name, value in params.items()
         ]
Esempio n. 19
0
    def start_fixture(self, parent_uuid, uuid, name, parameters):
        parameters = [Parameter(name=param_name, value=param_value) for param_name, param_value in parameters.items()]

        if name in FIXTURES and not self.fixture_context:
            group = TestResultContainer(uuid=uuid4())
            self.logger.start_group(group.uuid, group)
            self.fixture_context.append(group)

        if name in BEFORE_FIXTURES:
            fixture = TestBeforeResult(name=name, start=now(), parameters=parameters)
            for group in self.fixture_context:
                self.logger.start_before_fixture(group.uuid, uuid, fixture)

        elif name in AFTER_FIXTURES:
            fixture = TestAfterResult(name=name, start=now(), parameters=parameters)
            for group in self.fixture_context:
                self.logger.start_after_fixture(group.uuid, uuid, fixture)
Esempio n. 20
0
    def stop_step(self, uuid, exc_type, exc_val, exc_tb):
        status = Status.PASSED
        if exc_type is not None:
            if exc_type == pytest.skip.Exception:
                status = Status.SKIPPED
            else:
                status = Status.FAILED

        self.allure_logger.stop_step(uuid, stop=now(), status=status)
Esempio n. 21
0
    def start_step(self, uuid, title, params):
        def truncate(x):
            if len(x) > 200:
                return x[:180] + " ... " + x[-15:]
            return x

        parameters = [Parameter(name=name, value=truncate(value)) for name, value in params.items()]
        step = TestStepResult(name=title, start=now(), parameters=parameters)
        self.allure_logger.start_step(None, uuid, step)
 def start_new_test(self, name, attributes):
     uuid = uuid4()
     self.reporter.get_last_item(TestResultContainer).children.append(uuid)
     self.stack.append(uuid)
     test_case = TestResult(uuid=uuid,
                            historyId=md5(attributes.get('longname')),
                            name=name,
                            fullName=attributes.get('longname'),
                            start=now())
     self.reporter.schedule_test(uuid, test_case)
Esempio n. 23
0
 def stop_scenario(self, scenario):
     status = scenario_status(scenario)
     status_details = scenario_status_details(scenario)
     self.logger.update_test(self.current_scenario_uuid,
                             stop=now(),
                             status=status,
                             statusDetails=status_details)
     self.logger.close_test(self.current_scenario_uuid)
     self.current_scenario_uuid = None
     self.current_step_uuid = None
 def start_new_test(self, name, attributes):
     uuid = uuid4()
     self.reporter.get_last_item(TestResultContainer).children.append(uuid)
     self.stack.append(uuid)
     test_case = TestResult(uuid=uuid,
                            historyId=md5(attributes.get('longname')),
                            name=name,
                            fullName=attributes.get('longname'),
                            start=now())
     self.reporter.schedule_test(uuid, test_case)
Esempio n. 25
0
    def start_test(self, name, attributes):
        uuid = uuid4()
        with self.lifecycle.schedule_test_case(uuid=uuid) as test_result:
            long_name = attributes.get('longname')
            test_result.name = name
            test_result.fullName = long_name
            test_result.historyId = md5(long_name)
            test_result.start = now()

        for container in self.lifecycle.containers():
            container.children.append(uuid)
 def start_new_group(self, name, attributes):
     uuid = uuid4()
     self.set_suite_link(attributes.get('metadata'), uuid)
     if self.stack:
         parent_suite = self.reporter.get_last_item(TestResultContainer)
         parent_suite.children.append(uuid)
     self.stack.append(uuid)
     suite = TestResultContainer(uuid=uuid,
                                 name=name,
                                 description=attributes.get('doc'),
                                 start=now())
     self.reporter.start_group(uuid, suite)
 def start_new_group(self, name, attributes):
     uuid = uuid4()
     self.set_suite_link(attributes.get('metadata'), uuid)
     if self.stack:
         parent_suite = self.reporter.get_last_item(TestResultContainer)
         parent_suite.children.append(uuid)
     self.stack.append(uuid)
     suite = TestResultContainer(uuid=uuid,
                                 name=name,
                                 description=attributes.get('doc'),
                                 start=now())
     self.reporter.start_group(uuid, suite)
Esempio n. 28
0
    def start_behave_step(self, step):

        self.current_step_uuid = uuid4()
        name = u'{keyword} {title}'.format(keyword=step.keyword, title=step.name)

        allure_step = TestStepResult(name=name, start=now())
        self.logger.start_step(None, self.current_step_uuid, allure_step)

        if step.text:
            self.logger.attach_data(uuid4(), step.text, name='.text', attachment_type=AttachmentType.TEXT)

        if step.table:
            self.logger.attach_data(uuid4(), step_table(step), name='.table', attachment_type=AttachmentType.CSV)
Esempio n. 29
0
    def pytest_fixture_setup(self, fixturedef, request):
        fixture_name = fixturedef.argname

        container_uuid = self._cache.get(fixturedef)

        if not container_uuid:
            container_uuid = self._cache.set(fixturedef)
            container = TestResultContainer(uuid=container_uuid)
            self.allure_logger.start_group(container_uuid, container)

        self.allure_logger.update_group(container_uuid, start=now())

        before_fixture_uuid = uuid4()
        before_fixture = TestBeforeResult(name=fixture_name, start=now())
        self.allure_logger.start_before_fixture(container_uuid, before_fixture_uuid, before_fixture)

        yield

        self.allure_logger.stop_before_fixture(before_fixture_uuid, stop=now())

        for index, finalizer in enumerate(fixturedef._finalizer or ()):
            name = u'{fixture}::{finalizer}'.format(fixture=fixturedef.argname, finalizer=finalizer.__name__)
            fixturedef._finalizer[index] = allure_commons.fixture(finalizer, parent_uuid=container_uuid, name=name)
Esempio n. 30
0
def test_duration(allured_testdir, snipped):
    allured_testdir.testdir.makepyfile("""
        def test_duration_example():
            {snipped}
    """.format(snipped=snipped))

    timestamp = now()
    allured_testdir.run_with_allure()

    assert_that(
        allured_testdir.allure_report,
        has_test_case(
            "test_duration_example",
            all_of(has_entry("start", greater_than(timestamp)),
                   has_entry("stop", greater_than(timestamp)))))
Esempio n. 31
0
 def stop_current_test(self, name, attributes):
     uuid = self.stack.pop()
     test = self.reporter.get_test(uuid)
     test.status = utils.get_allure_status(attributes.get('status'))
     test.labels.extend(utils.get_allure_suites(attributes.get('longname')))
     test.labels.extend(utils.get_allure_tags(attributes.get('tags')))
     test.labels.append(utils.get_allure_thread(self.pool_id))
     test.labels.append(Label(LabelType.HOST, value=host_tag()))
     test.statusDetails = StatusDetails(message=attributes.get('message'))
     test.description = attributes.get('doc')
     last_link = list(self.links.values())[-1] if self.links else None
     if last_link:
         test.links.append(Link(LinkType.LINK, last_link, 'Link'))
     test.stop = now()
     self.reporter.close_test(uuid)
Esempio n. 32
0
    def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb):
        scenario = context['scenario']
        self.flush_steps()
        status = scenario_status(scenario)
        status_details = scenario_status_details(scenario)
        self.logger.update_test(uuid, stop=now(), status=status, statusDetails=status_details)
        self.logger.close_test(uuid)
        self.current_step_uuid = None

        for group in self.fixture_context.exit():
            group.children.append(uuid)
            self.logger.stop_group(group.uuid)

        self.execution_context.exit()
        self.execution_context.append(uuid)
Esempio n. 33
0
    def start(self):
        if self.reporter is None:
            return

        self.test_uuid = uuid4()
        self.test_case = TestResult(uuid=self.test_uuid, start=now())
        self.test_case.fullname = self.job.fullname

        self._build_testcase_name()

        if self.job.description is not None:
            self.test_case.description = self.job.description

        self.reporter.schedule_test(self.test_uuid, self.test_case)

        pass
def test_duration(allured_testdir, snipped):
    allured_testdir.testdir.makepyfile("""
        def test_duration_example():
            {snipped}
    """.format(snipped=snipped))

    timestamp = now()
    allured_testdir.run_with_allure()

    assert_that(allured_testdir.allure_report,
                has_test_case("test_duration_example",
                              all_of(
                                  has_entry("start", greater_than(timestamp)),
                                  has_entry("stop", greater_than(timestamp))
                              ))
                )
    def pytest_bdd_before_scenario(self, request, feature, scenario):
        uuid = get_uuid(request.node.nodeid)
        full_name = get_full_name(feature, scenario)
        name = get_name(request.node, scenario)
        with self.lifecycle.schedule_test_case(uuid=uuid) as test_result:
            test_result.fullName = full_name
            test_result.name = name
            test_result.start = now()
            test_result.labels.append(Label(name=LabelType.HOST, value=self.host))
            test_result.labels.append(Label(name=LabelType.THREAD, value=self.thread))
            test_result.labels.append(Label(name=LabelType.FRAMEWORK, value="pytest-bdd"))
            test_result.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
            test_result.labels.append(Label(name=LabelType.FEATURE, value=feature.name))
            test_result.parameters = get_params(request.node)

        finalizer = partial(self._scenario_finalizer, scenario)
        request.node.addfinalizer(finalizer)
Esempio n. 36
0
def after_step(context, step):
    context.logger.debug(">>> step '{}' {}".format(step.name, step.status))

    if step.status == "passed":
        my_status = Status.PASSED
    elif step.status == "skipped":
        my_status = Status.SKIPPED
    elif step.status == "undefined":
        my_status = Status.BROKEN
    else:
        my_status = Status.FAILED
        noww = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        context.logger.debug(f"take step Screenshot-{noww}")
        context.allure.attach_data(
            context.current_step_uuid,
            context.browser.get_screenshot_as_png(),
            name=f"Screenshot-step-{noww}", attachment_type=AttachmentType.PNG)
    context.allure.stop_step(context.current_step_uuid, stop=now(), status=my_status)
Esempio n. 37
0
    def start_scenario(self, scenario):
        self.current_scenario_uuid = uuid4()
        self.fixture_context.enter()
        self.execution_context.enter()
        self.execution_context.append(self.current_scenario_uuid)

        test_case = TestResult(uuid=self.current_scenario_uuid, start=now())
        test_case.name = scenario_name(scenario)
        test_case.historyId = scenario_history_id(scenario)
        test_case.description = '\n'.join(scenario.description)
        test_case.parameters = scenario_parameters(scenario)
        test_case.labels.extend([Label(name=LabelType.TAG, value=tag) for tag in scenario_tags(scenario)])
        test_case.labels.append(Label(name=LabelType.SEVERITY, value=scenario_severity(scenario).value))
        test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
        test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
        test_case.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))

        self.logger.schedule_test(self.current_scenario_uuid, test_case)
Esempio n. 38
0
 def stop_step(self, uuid, exc_type, exc_val, exc_tb):
     """stop step"""
     step_data = self._cache.get(uuid)
     out = sys.stdout.getvalue()
     sys.stdout.close()
     if len(out) != 0:
         self.attach_data(out, "STDOUT", AttachmentType.TEXT, "txt")
     sys.stdout = step_data.prev_stdout
     err = sys.stderr.getvalue()
     sys.stderr.close()
     if len(err) != 0:
         self.attach_data(err, "STDERR", AttachmentType.TEXT, "txt")
     sys.stderr = step_data.prev_stderr
     self.allure_logger.stop_step(
         uuid,
         stop=now(),
         status=get_status(exc_val),
         statusDetails=get_status_details(exc_type, exc_val, exc_tb),
     )
Esempio n. 39
0
    def stop_scenario(self, scenario):
        if scenario.status == 'skipped' and not self.behave_config.show_skipped:
            self.logger.drop_test(self.current_scenario_uuid)
        else:
            status = scenario_status(scenario)
            status_details = scenario_status_details(scenario)

            self.flush_steps()
            test_result = self.logger.get_test(self.current_scenario_uuid)
            test_result.stop = now()
            test_result.status = status
            test_result.statusDetails = status_details
            self.logger.close_test(self.current_scenario_uuid)
            self.current_step_uuid = None

            for group in self.fixture_context.exit():
                group.children.append(self.current_scenario_uuid)
                self.logger.stop_group(group.uuid)

        self.execution_context.exit()
        self.execution_context.append(self.current_scenario_uuid)
        self.current_scenario_uuid = None
 def end_current_keyword(self, name, attributes):
     uuid = self.stack.pop()
     if uuid in self.items_log:
         self.reporter.attach_data(uuid=uuid4(),
                                   body=self.items_log.pop(uuid).replace('\n', '<br>'),
                                   name='Keyword Log',
                                   attachment_type=AttachmentType.HTML)
     args = {
         'uuid': uuid,
         'status': utils.get_allure_status(attributes.get('status')),
         'stop': now()
     }
     keyword_type = attributes.get('type')
     parent_item = self.reporter.get_last_item()
     if keyword_type in RobotKeywordType.FIXTURES and not isinstance(parent_item, TestStepResult):
         if keyword_type == RobotKeywordType.SETUP:
             self.reporter.stop_before_fixture(**args)
             return
         elif keyword_type == RobotKeywordType.TEARDOWN:
             self.reporter.stop_after_fixture(**args)
             return
     self.reporter.stop_step(**args)
def test_with_fixture_finalizer_duration(allured_testdir, snipped):
    allured_testdir.testdir.makepyfile("""
        import pytest

        @pytest.fixture
        def fixture(request):
            def finalizer():
                {snipped}
            request.addfinalizef(finalizer)

        def test_with_fixture_finalizer_duration(fixture):
            pass
    """.format(snipped=snipped))

    timestamp = now()
    allured_testdir.run_with_allure()

    assert_that(allured_testdir.allure_report,
                has_test_case("test_with_fixture_finalizer_duration",
                              all_of(
                                  has_entry("start", greater_than(timestamp)),
                                  has_entry("stop", greater_than(timestamp))
                              ))
                )
    def stop_current_test(self, name, attributes):
        uuid = self.stack.pop()
        test = self.reporter.get_test(uuid)
        test.status = utils.get_allure_status(attributes.get('status'))
        test.labels.extend(utils.get_allure_suites(attributes.get('longname')))

        test.labels.extend(allure_tags(attributes))
        for label_type in (LabelType.EPIC, LabelType.FEATURE, LabelType.STORY):
            test.labels.extend(allure_labels(attributes, label_type))
        for link_type in (LinkType.ISSUE, LinkType.TEST_CASE, LinkType.LINK):
            test.links.extend(allure_links(attributes, link_type))
        test.labels.append(Label(name=LabelType.THREAD, value=self.pool_id))
        test.labels.append(Label(name=LabelType.HOST, value=host_tag()))
        test.labels.append(Label(name=LabelType.FRAMEWORK, value='robotframework'))
        test.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
        test.statusDetails = StatusDetails(message=attributes.get('message'), trace=self.get_traceback_message())
        test.description = attributes.get('doc')
        last_link = list(self.links.values())[-1] if self.links else None
        if attributes.get(Severity.CRITICAL, 'no') == 'yes':
            test.labels.append(Label(name=LabelType.SEVERITY, value=Severity.CRITICAL))
        if last_link:
            test.links.append(Link(LinkType.LINK, last_link, 'Link'))
        test.stop = now()
        self.reporter.close_test(uuid)
Esempio n. 43
0
 def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
     self.allure_logger.stop_after_fixture(uuid,
                                           stop=now(),
                                           status=get_status(exc_val),
                                           statusDetails=get_status_details(exc_type, exc_val, exc_tb))
Esempio n. 44
0
 def start_fixture(self, parent_uuid, uuid, name):
     after_fixture = TestAfterResult(name=name, start=now())
     self.allure_logger.start_after_fixture(parent_uuid, uuid, after_fixture)
Esempio n. 45
0
 def stop_behave_step(self, result):
     status = step_status(result)
     status_details = step_status_details(result)
     self.logger.stop_step(self.current_step_uuid, stop=now(), status=status, statusDetails=status_details)
Esempio n. 46
0
 def start_step(self, uuid, title, params):
     parameters = [Parameter(name=name, value=value) for name, value in params.items()]
     step = TestStepResult(name=title, start=now(), parameters=parameters)
     self.logger.start_step(None, uuid, step)
Esempio n. 47
0
 def stop_step(self, uuid, exc_type, exc_val, exc_tb):
     self.logger.stop_step(uuid,
                           stop=now(),
                           status=get_status(exc_val),
                           statusDetails=get_status_details(exc_type, exc_val, exc_tb))
Esempio n. 48
0
 def stop_after_fixture(self, uuid, **kwargs):
     self._update_item(uuid, **kwargs)
     fixture = self._items.pop(uuid)
     fixture.stop = now()
Esempio n. 49
0
 def pytest_fixture_post_finalizer(self, fixturedef):
     yield
     if hasattr(fixturedef, 'cached_result') and self._cache.get(fixturedef):
         container_uuid = self._cache.pop(fixturedef)
         self.allure_logger.stop_group(container_uuid, stop=now())
Esempio n. 50
0
 def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
     if name in FIXTURES:
         self.logger.stop_before_fixture(uuid=uuid,
                                         stop=now(),
                                         status=get_status(exc_val),
                                         statusDetails=get_status_details(exc_type, exc_val, exc_tb))
 def stop_current_group(self):
     uuid = self.stack.pop()
     self.remove_suite_link(uuid)
     self.reporter.stop_group(uuid, stop=now())
Esempio n. 52
0
 def pytest_runtest_protocol(self, item, nextitem):
     uuid = self._cache.push(item.nodeid)
     test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
     self.allure_logger.schedule_test(uuid, test_result)
     yield