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


Python python.Module方法代码示例

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


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

示例1: collect_by_name

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def collect_by_name(
        self, modcol: Module, name: str
    ) -> Optional[Union[Item, Collector]]:
        """Return the collection node for name from the module collection.

        This will search a module collection node for a collection node
        matching the given name.

        :param modcol: a module collection node; see :py:meth:`getmodulecol`

        :param name: the name of the node to return
        """
        if modcol not in self._mod_collections:
            self._mod_collections[modcol] = list(modcol.collect())
        for colitem in self._mod_collections[modcol]:
            if colitem.name == name:
                return colitem
        return None 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:pytester.py

示例2: _parametrize

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def _parametrize(
        self, cls: Optional[Type], definition: FunctionDefinition, fixtureinfo: FuncFixtureInfo
    ) -> Metafunc:
        module = self.getparent(Module).obj
        metafunc = Metafunc(definition, fixtureinfo, self.config, cls=cls, module=module)
        methods = []
        if hasattr(module, "pytest_generate_tests"):
            methods.append(module.pytest_generate_tests)
        if hasattr(cls, "pytest_generate_tests"):
            cls = cast(Type, cls)
            methods.append(cls().pytest_generate_tests)
        self.ihook.pytest_generate_tests.call_extra(methods, {"metafunc": metafunc})
        return metafunc 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:15,代码来源:pytest_plugin.py

示例3: pytest_make_collect_report

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def pytest_make_collect_report(self, collector: nodes.Collector) -> Generator:
        if isinstance(collector, Session):
            out = yield
            res = out.get_result()  # type: CollectReport

            # Sort any lf-paths to the beginning.
            lf_paths = self.lfplugin._last_failed_paths
            res.result = sorted(
                res.result, key=lambda x: 0 if Path(str(x.fspath)) in lf_paths else 1,
            )
            return

        elif isinstance(collector, Module):
            if Path(str(collector.fspath)) in self.lfplugin._last_failed_paths:
                out = yield
                res = out.get_result()
                result = res.result
                lastfailed = self.lfplugin.lastfailed

                # Only filter with known failures.
                if not self._collected_at_least_one_failure:
                    if not any(x.nodeid in lastfailed for x in result):
                        return
                    self.lfplugin.config.pluginmanager.register(
                        LFPluginCollSkipfiles(self.lfplugin), "lfplugin-collskip"
                    )
                    self._collected_at_least_one_failure = True

                session = collector.session
                result[:] = [
                    x
                    for x in result
                    if x.nodeid in lastfailed
                    # Include any passed arguments (not trivial to filter).
                    or session.isinitpath(x.fspath)
                    # Keep all sub-collectors.
                    or isinstance(x, nodes.Collector)
                ]
                return
        yield 
开发者ID:pytest-dev,项目名称:pytest,代码行数:42,代码来源:cacheprovider.py

示例4: __init__

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def __init__(self, request: FixtureRequest, tmpdir_factory: TempdirFactory) -> None:
        self.request = request
        self._mod_collections = (
            WeakKeyDictionary()
        )  # type: WeakKeyDictionary[Module, List[Union[Item, Collector]]]
        if request.function:
            name = request.function.__name__  # type: str
        else:
            name = request.node.name
        self._name = name
        self.tmpdir = tmpdir_factory.mktemp(name, numbered=True)
        self.test_tmproot = tmpdir_factory.mktemp("tmp-" + name, numbered=True)
        self.plugins = []  # type: List[Union[str, _PluggyPlugin]]
        self._cwd_snapshot = CwdSnapshot()
        self._sys_path_snapshot = SysPathsSnapshot()
        self._sys_modules_snapshot = self.__take_sys_modules_snapshot()
        self.chdir()
        self.request.addfinalizer(self.finalize)
        self._method = self.request.config.getoption("--runpytest")

        mp = self.monkeypatch = MonkeyPatch()
        mp.setenv("PYTEST_DEBUG_TEMPROOT", str(self.test_tmproot))
        # Ensure no unexpected caching via tox.
        mp.delenv("TOX_ENV_DIR", raising=False)
        # Discard outer pytest options.
        mp.delenv("PYTEST_ADDOPTS", raising=False)
        # Ensure no user config is used.
        tmphome = str(self.tmpdir)
        mp.setenv("HOME", tmphome)
        mp.setenv("USERPROFILE", tmphome)
        # Do not use colors for inner runs by default.
        mp.setenv("PY_COLORS", "0") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:34,代码来源:pytester.py

示例5: pytest_pycollect_makemodule

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def pytest_pycollect_makemodule(path: py.path.local, parent) -> Optional["Module"]:
    """Return a Module collector or None for the given path.

    This hook will be called for each matching test module path.
    The pytest_collect_file hook needs to be used if you want to
    create test modules for files that do not match as a test module.

    Stops at first non-None result, see :ref:`firstresult`.

    :param path: a :py:class:`py.path.local` - the path of module to collect
    """ 
开发者ID:pytest-dev,项目名称:pytest,代码行数:13,代码来源:hookspec.py

示例6: test_pytest_pycollect_module

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def test_pytest_pycollect_module(self, testdir):
        testdir.makeconftest(
            """
            import pytest
            class MyModule(pytest.Module):
                pass
            def pytest_pycollect_makemodule(path, parent):
                if path.basename == "test_xyz.py":
                    return MyModule(path, parent)
        """
        )
        testdir.makepyfile("def test_some(): pass")
        testdir.makepyfile(test_xyz="def test_func(): pass")
        result = testdir.runpytest("--collect-only")
        result.stdout.fnmatch_lines(["*<Module*test_pytest*", "*<MyModule*xyz*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:17,代码来源:collect.py

示例7: test_makeitem_non_underscore

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def test_makeitem_non_underscore(self, testdir, monkeypatch):
        modcol = testdir.getmodulecol("def _hello(): pass")
        values = []
        monkeypatch.setattr(
            pytest.Module, "_makeitem", lambda self, name, obj: values.append(name)
        )
        values = modcol.collect()
        assert "_hello" not in values 
开发者ID:pytest-dev,项目名称:pytest,代码行数:10,代码来源:collect.py

示例8: test_issue2369_collect_module_fileext

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def test_issue2369_collect_module_fileext(self, testdir):
        """Ensure we can collect files with weird file extensions as Python
        modules (#2369)"""
        # We'll implement a little finder and loader to import files containing
        # Python source code whose file extension is ".narf".
        testdir.makeconftest(
            """
            import sys, os, imp
            from _pytest.python import Module

            class Loader(object):
                def load_module(self, name):
                    return imp.load_source(name, name + ".narf")
            class Finder(object):
                def find_module(self, name, path=None):
                    if os.path.exists(name + ".narf"):
                        return Loader()
            sys.meta_path.append(Finder())

            def pytest_collect_file(path, parent):
                if path.ext == ".narf":
                    return Module(path, parent)"""
        )
        testdir.makefile(
            ".narf",
            """\
            def test_something():
                assert 1 + 1 == 2""",
        )
        # Use runpytest_subprocess, since we're futzing with sys.meta_path.
        result = testdir.runpytest_subprocess()
        result.stdout.fnmatch_lines(["*1 passed*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:34,代码来源:collect.py

示例9: _add_item_hier_parts_other

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def _add_item_hier_parts_other(item_parts, item, item_type, hier_flag,
                                   report_parts, rp_name=""):
        """
        Add item to hierarchy of parents.

        :param item_parts:  Parent_items
        :param item:        pytest.Item
        :param item_type:   (SUITE, STORY, TEST, SCENARIO, STEP, BEFORE_CLASS,
         BEFORE_GROUPS, BEFORE_METHOD, BEFORE_SUITE, BEFORE_TEST, AFTER_CLASS,
        AFTER_GROUPS, AFTER_METHOD, AFTER_SUITE, AFTER_TEST)
        :param hier_flag:    bool state
        :param report_parts: list of parent reports
        :param rp_name:      report name
        :return: str rp_name
        """
        for part in item_parts:

            if type(part) is item_type:

                if item_type is Module:
                    module_path = str(
                        item.fspath.new(dirname=rp_name,
                                        basename=part.fspath.basename,
                                        drive=""))
                    rp_name = module_path if rp_name else module_path[1:]
                elif item_type in (Class, Function, UnitTestCase,
                                   TestCaseFunction):
                    rp_name += ("::" if rp_name else "") + part.name

                if hier_flag:
                    part._rp_name = rp_name
                    rp_name = ""
                    report_parts.append(part)

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

示例10: _get_item_description

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def _get_item_description(test_item):
        """
        Get description of item.

        :param test_item: pytest.Item
        :return string description
        """
        if isinstance(test_item, (Class, Function, Module, Item)):
            doc = test_item.obj.__doc__
            if doc is not None:
                return trim_docstring(doc)
        if isinstance(test_item, DoctestItem):
            return test_item.reportinfo()[2] 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:15,代码来源:service.py

示例11: interface_hook_creator

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Module [as 别名]
def interface_hook_creator(package_path, common_filename, fixture_name):
    def create_interface_hooks(meta_fixture, name):
        tests_node_id = os.path.join(package_path, '{}.py'.format(name))

        def pytest_runtest_protocol(item, nextitem):
            filename, *test_name = item.nodeid.split('::')

            if filename == tests_node_id and fixture_name in item.fixturenames:
                fixture = _remap_fixture(item, meta_fixture.__name__, fixture_name)

                for dep_fixt_name in chain.from_iterable(e.argnames for e in fixture):
                    _remap_fixture(item, dep_fixt_name, dep_fixt_name)

        def _remap_fixture(item, actual_name, expected_name):
            fixture = tuple(item.session._fixturemanager._arg2fixturedefs[actual_name])
            item._request._arg2fixturedefs[expected_name] = fixture
            return fixture

        @pytest.hookimpl(hookwrapper=True)
        def pytest_collect_file(path, parent):
            outcome = yield
            result = outcome.get_result()

            if parent.parent is None:
                result.append(
                    DoctestModule(os.path.join(parent.fspath, package_path, 'conftest.py'), parent,
                                  nodeid=os.path.join(package_path, '{}_conf.py'.format(name))))

                result.append(Module(os.path.join(parent.fspath, package_path, common_filename), parent,
                                     nodeid=tests_node_id))

        return pytest_runtest_protocol, pytest_collect_file

    return create_interface_hooks 
开发者ID:zyfra,项目名称:ebonite,代码行数:36,代码来源:conftest.py


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