當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。