def pytest_runtest_setup(self, item):
        uuid = self._cache.set(item.nodeid)
        test_result = TestResult(name=item.name, uuid=uuid)
        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.set(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()
        ])
Ejemplo n.º 2
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()])
Ejemplo n.º 3
0
    def pytest_runtest_protocol(self, item, nextitem):
        uuid = self._cache.set(item.nodeid)
        for fixturedef in _test_fixtures(item):
            group_uuid = self._cache.get(fixturedef)
            if not group_uuid:
                group_uuid = self._cache.set(fixturedef)
                group = TestResultContainer(uuid=group_uuid)
                self.allure_logger.start_group(group_uuid, group)
            self.allure_logger.update_group(group_uuid, children=uuid)

        test_case = TestResult(name=allure_name(item), uuid=uuid)
        self.allure_logger.schedule_test(uuid, test_case)

        if hasattr(item, 'function'):
            test_case.description = item.function.__doc__

        yield

        for name, value in item.callspec.params.items() if hasattr(
                item, 'callspec') else ():
            test_result = self.allure_logger.get_test(uuid)
            if test_result:
                test_result.parameters.append(Parameter(
                    name, represent(value)))

        test_case.labels.extend([
            Label(name=name, value=value)
            for name, value in allure_labels(item)
        ])
        test_case.labels.extend([
            Label(name=LabelType.TAG, value=value)
            for value in pytest_markers(item)
        ])
        test_case.labels.append(Label(name=LabelType.HOST, value=self._host))
        test_case.labels.append(
            Label(name=LabelType.THREAD, value=self._thread))
        test_case.labels.append(Label(name=LabelType.FRAMEWORK,
                                      value='pytest'))
        test_case.labels.append(
            Label(name=LabelType.LANGUAGE, value=platform_label()))

        test_case.links += [
            Link(link_type, url, name)
            for link_type, url, name in allure_links(item)
        ]

        test_case.fullName = allure_full_name(item)
        test_case.historyId = md5(test_case.fullName)
        test_case.labels.append(Label('package', allure_package(item)))

        uuid = self._cache.pop(item.nodeid)
        self.allure_logger.close_test(uuid)