当前位置: 首页>>代码示例>>Python>>正文


Python pytest.Item方法代码示例

本文整理汇总了Python中pytest.Item方法的典型用法代码示例。如果您正苦于以下问题:Python pytest.Item方法的具体用法?Python pytest.Item怎么用?Python pytest.Item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytest的用法示例。


在下文中一共展示了pytest.Item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pytest_runtest_teardown

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def pytest_runtest_teardown(item: pytest.Item):
    """Hook to run after every test."""
    # Inject footer at end of test, may be followed by additional teardown.
    # Don't do this when running in teamcity, where it's redundant.
    if not teamcity.is_running_under_teamcity():
        global start_time
        duration = time.time() - start_time
        start_time = 0
        print(
            """
==========
======= END: {}::{} ({})
==========""".format(
                sdk_diag.get_test_suite_name(item), item.name, sdk_utils.pretty_duration(duration)
            )
        ) 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:18,代码来源:conftest.py

示例2: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def pytest_runtest_setup(item: pytest.Item):
    """Hook to run before every test."""
    # Inject header at start of test, following automatic "path/to/test_file.py::test_name":
    # Don't do this when running in teamcity, where it's redundant.
    if not teamcity.is_running_under_teamcity():
        global start_time
        start_time = time.time()
        print(
            """
==========
======= START: {}::{}
==========""".format(
                sdk_diag.get_test_suite_name(item), item.name
            )
        )

    if INTEGRATION_TEST_LOG_COLLECTION:
        sdk_diag.handle_test_setup(item)
    sdk_utils.check_dcos_min_version_mark(item) 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:21,代码来源:conftest.py

示例3: _whitelisted_service_names

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _whitelisted_service_names(item: pytest.Item) -> Set[str]:
    """Returns a set of whitelisted service names configured by pytest marker diag_service_whitelist,
    which should be used like this:

    @pytest.mark.diag_service_whitelist(set('service1', 'service2'))
    def your_test_here(): ...

    Note that the diag_service_whitelist marker can be used on function, class, or module
    to be able to hierarchically configure the whitelist.
    """
    if item.get_closest_marker(name='diag_service_whitelist') is None:
        return set()

    whitelisted_service_names: Set[str] = set()
    for mark in item.iter_markers(name='diag_service_whitelist'):
        whitelisted_service_names = whitelisted_service_names.union(mark.args[0])

    return whitelisted_service_names 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:20,代码来源:sdk_diag.py

示例4: _dump_plans

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _dump_plans(item: pytest.Item, service_name: str) -> None:
    """If the test had failed, writes the plan state(s) to log file(s)."""

    # Use brief timeouts, we just want a best-effort attempt here:
    plan_names = sdk_plan.list_plans(service_name, 5)
    for plan_name in plan_names:
        plan = sdk_plan.get_plan(service_name, plan_name, 5)
        # Include service name in plan filename, but be careful about folders...
        out_path = _setup_artifact_path(
            item, "plan_{}_{}.json".format(service_name.replace("/", "_"), plan_name)
        )
        out_content = json.dumps(plan, indent=2)
        log.info("=> Writing {} ({} bytes)".format(out_path, len(out_content)))
        with open(out_path, "w") as f:
            f.write(out_content)
            f.write("\n")  # ... and a trailing newline 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:18,代码来源:sdk_diag.py

示例5: _setup_artifact_path

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _setup_artifact_path(item: pytest.Item, artifact_name: str) -> str:
    """Given the pytest item and an artifact_name,
    Returns the path to write an artifact with that name."""

    # full item.listchain() is e.g.:
    # - ['build', 'frameworks/template/tests/test_sanity.py', 'test_install']
    # - ['build', 'tests/test_sanity.py', 'test_install']
    # we want to turn both cases into: 'logs/test_sanity_py/test_install'
    if _testlogs_test_index > 0:
        # test_index is defined: get name like "05__test_placement_rules"
        test_name = "{:02d}__{}".format(_testlogs_test_index, item.name)
    else:
        # test_index is not defined: fall back to just "test_placement_rules"
        test_name = item.name

    output_dir = os.path.join(_test_suite_artifact_directory(item), test_name)
    if not os.path.isdir(output_dir):
        os.makedirs(output_dir)

    return os.path.join(output_dir, artifact_name) 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:22,代码来源:sdk_diag.py

示例6: check_dcos_min_version_mark

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def check_dcos_min_version_mark(item: pytest.Item) -> None:
    """Enforces the dcos_min_version pytest annotation, which should be used like this:

    @pytest.mark.dcos_min_version('1.10')
    def your_test_here(): ...

    In order for this annotation to take effect, this function must be called by a pytest_runtest_setup() hook.
    """
    min_version_mark = item.get_closest_marker("dcos_min_version")
    if min_version_mark:
        min_version = min_version_mark.args[0]
        message = "Feature only supported in DC/OS {} and up".format(min_version)
        if "reason" in min_version_mark.kwargs:
            message += ": {}".format(min_version_mark.kwargs["reason"])
        if dcos_version_less_than(min_version):
            pytest.skip(message) 
开发者ID:mesosphere,项目名称:dcos-kafka-service,代码行数:18,代码来源:sdk_utils.py

示例7: dummy_yaml_custom_test

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def dummy_yaml_custom_test(testdir):
    """Writes a conftest file that collects and executes a dummy yaml test.

    Taken from the docs, but stripped down to the bare minimum, useful for
    tests which needs custom items collected.
    """
    testdir.makeconftest(
        """
        import pytest

        def pytest_collect_file(parent, path):
            if path.ext == ".yaml" and path.basename.startswith("test"):
                return YamlFile(path, parent)

        class YamlFile(pytest.File):
            def collect(self):
                yield YamlItem(self.fspath.basename, self)

        class YamlItem(pytest.Item):
            def runtest(self):
                pass
    """
    )
    testdir.makefile(".yaml", test1="") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:conftest.py

示例8: test_multiple_items_per_collector_byid

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def test_multiple_items_per_collector_byid(self, testdir):
        c = testdir.makeconftest(
            """
            import pytest
            class MyItem(pytest.Item):
                def runtest(self):
                    pass
            class MyCollector(pytest.File):
                def collect(self):
                    return [MyItem(name="xyz", parent=self)]
            def pytest_collect_file(path, parent):
                if path.basename.startswith("conftest"):
                    return MyCollector(path, parent)
        """
        )
        result = testdir.runpytest(c.basename + "::" + "xyz")
        assert result.ret == 0
        result.stdout.fnmatch_lines(["*1 pass*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:acceptance_test.py

示例9: test_xfail_item

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def test_xfail_item(testdir):
    # Ensure pytest.xfail works with non-Python Item
    testdir.makeconftest(
        """
        import pytest

        class MyItem(pytest.Item):
            nodeid = 'foo'
            def runtest(self):
                pytest.xfail("Expected Failure")

        def pytest_collect_file(path, parent):
            return MyItem("foo", parent)
    """
    )
    result = testdir.inline_run()
    passed, skipped, failed = result.listoutcomes()
    assert not failed
    xfailed = [r for r in skipped if hasattr(r, "wasxfail")]
    assert xfailed 
开发者ID:pytest-dev,项目名称:pytest,代码行数:22,代码来源:test_skipping.py

示例10: test_mark_xfail_item

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def test_mark_xfail_item(testdir):
    # Ensure pytest.mark.xfail works with non-Python Item
    testdir.makeconftest(
        """
        import pytest

        class MyItem(pytest.Item):
            nodeid = 'foo'
            def setup(self):
                marker = pytest.mark.xfail("1 == 2", reason="Expected failure - false")
                self.add_marker(marker)
                marker = pytest.mark.xfail(True, reason="Expected failure - true")
                self.add_marker(marker)
            def runtest(self):
                assert False

        def pytest_collect_file(path, parent):
            return MyItem("foo", parent)
    """
    )
    result = testdir.inline_run()
    passed, skipped, failed = result.listoutcomes()
    assert not failed
    xfailed = [r for r in skipped if hasattr(r, "wasxfail")]
    assert xfailed 
开发者ID:pytest-dev,项目名称:pytest,代码行数:27,代码来源:test_skipping.py

示例11: __init__

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def __init__(self, py_test_service,
                 log_level=logging.NOTSET,
                 endpoint=None):
        """Initialize RPReport Listener instance.

        :param py_test_service: PyTestServiceClass instance
        :param log_level:       One of the 'CRITICAL', 'ERROR',
                                'WARNING','INFO','DEBUG', 'NOTSET'
        :param endpoint:        Report Portal API endpoint
        """
        # Test Item result
        self.PyTestService = py_test_service
        self.result = None
        self.issue = {}
        self._log_level = log_level
        if PYTEST_HAS_LOGGING_PLUGIN:
            self._log_handler = \
                RPLogHandler(py_test_service=py_test_service,
                             level=log_level,
                             filter_client_logs=True,
                             endpoint=endpoint) 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:23,代码来源:listener.py

示例12: pytest_runtest_protocol

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def pytest_runtest_protocol(self, item):
        """
        Adding issues id marks to the test item.

        :param item:  Pytest.Item
        :return: generator object
        """
        self._add_issue_id_marks(item)
        item_id = self.PyTestService.start_pytest_item(item)
        if PYTEST_HAS_LOGGING_PLUGIN:
            # This check can go away once we support pytest >= 3.3
            with patching_logger_class():
                with _pytest.logging.catching_logs(self._log_handler,
                                                   level=self._log_level):
                    yield
        else:
            yield
        # Finishing item in RP
        self.PyTestService.finish_pytest_item(
            item, item_id, self.result or 'SKIPPED', self.issue or None) 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:22,代码来源:listener.py

示例13: _get_item_parts

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _get_item_parts(item):
        """
        Get item of parents.

        :param item: pytest.Item
        :return list of parents
        """
        parts = []
        parent = item.parent
        if not isinstance(parent, Instance):
            parts.append(parent)
        while True:
            parent = parent.parent
            if parent is None:
                break
            if isinstance(parent, Instance):
                continue
            if isinstance(parent, Session):
                break
            parts.append(parent)

        parts.reverse()
        return parts 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:25,代码来源:service.py

示例14: _get_item_dirs

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _get_item_dirs(item):
        """
        Get directory of item.

        :param item: pytest.Item
        :return: list of dirs
        """
        root_path = item.session.config.rootdir.strpath
        dir_path = item.fspath.new(basename="")
        rel_dir = dir_path.new(dirname=dir_path.relto(root_path), basename="",
                               drive="")

        dir_list = []
        for directory in rel_dir.parts(reverse=False):
            dir_name = directory.basename
            if dir_name:
                dir_list.append(dir_name)

        return dir_list 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:21,代码来源:service.py

示例15: _get_item_name

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Item [as 别名]
def _get_item_name(test_item):
        """
        Get name of item.

        :param test_item: pytest.Item
        :return: name
        """
        name = test_item._rp_name
        if len(name) > 256:
            name = name[:256]
            test_item.warn(
                PytestWarning(
                    'Test node ID was truncated to "{}" because of name size '
                    'constrains on reportportal'.format(name)
                )
            )
        return name 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:19,代码来源:service.py


注:本文中的pytest.Item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。