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


Python python.Function方法代码示例

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


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

示例1: fillfixtures

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def fillfixtures(function: "Function") -> None:
    """ fill missing funcargs for a test function. """
    warnings.warn(FILLFUNCARGS, stacklevel=2)
    try:
        request = function._request
    except AttributeError:
        # XXX this special code path is only expected to execute
        # with the oejskit plugin.  It uses classes with funcargs
        # and we thus have to work a bit to allow this.
        fm = function.session._fixturemanager
        assert function.parent is not None
        fi = fm.getfixtureinfo(function.parent, function.obj, None)
        function._fixtureinfo = fi
        request = function._request = FixtureRequest(function)
        request._fillfixtures()
        # prune out funcargs for jstests
        newfuncargs = {}
        for name in fi.argnames:
            newfuncargs[name] = function.funcargs[name]
        function.funcargs = newfuncargs
    else:
        request._fillfixtures() 
开发者ID:pytest-dev,项目名称:pytest,代码行数:24,代码来源:fixtures.py

示例2: _gen_items

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def _gen_items(self, endpoint: Endpoint) -> Generator[Function, None, None]:
        """Generate all items for the given endpoint.

        Could produce more than one test item if
        parametrization is applied via ``pytest.mark.parametrize`` or ``pytest_generate_tests``.

        This implementation is based on the original one in pytest, but with slight adjustments
        to produce tests out of hypothesis ones.
        """
        name = self._get_test_name(endpoint)
        funcobj = self._make_test(endpoint)

        cls = self._get_class_parent()
        definition = create(FunctionDefinition, name=self.name, parent=self.parent, callobj=funcobj)
        fixturemanager = self.session._fixturemanager
        fixtureinfo = fixturemanager.getfixtureinfo(definition, funcobj, cls)

        metafunc = self._parametrize(cls, definition, fixtureinfo)

        if not metafunc._calls:
            yield create(SchemathesisFunction, name=name, parent=self.parent, callobj=funcobj, fixtureinfo=fixtureinfo)
        else:
            fixtures.add_funcarg_pseudo_fixture_def(self.parent, metafunc, fixturemanager)
            fixtureinfo.prune_dependency_tree()
            for callspec in metafunc._calls:
                subname = "{}[{}]".format(name, callspec.id)
                yield create(
                    SchemathesisFunction,
                    name=subname,
                    parent=self.parent,
                    callspec=callspec,
                    callobj=funcobj,
                    fixtureinfo=fixtureinfo,
                    keywords={callspec.id: True},
                    originalname=name,
                ) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:38,代码来源:pytest_plugin.py

示例3: collect

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def collect(self) -> List[Function]:  # type: ignore
        """Generate different test items for all endpoints available in the given schema."""
        try:
            return [
                item for endpoint in self.schemathesis_case.get_all_endpoints() for item in self._gen_items(endpoint)
            ]
        except Exception:
            pytest.fail("Error during collection") 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:10,代码来源:pytest_plugin.py

示例4: is_potential_nosetest

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def is_potential_nosetest(item):
    # extra check needed since we do not do nose style setup/teardown
    # on direct unittest style classes
    return isinstance(item, python.Function) and not isinstance(
        item, unittest.TestCaseFunction
    ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:8,代码来源:nose.py

示例5: pytest_pyfunc_call

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]:
    """ call underlying test function.

    Stops at first non-None result, see :ref:`firstresult` """ 
开发者ID:pytest-dev,项目名称:pytest,代码行数:6,代码来源:hookspec.py

示例6: is_potential_nosetest

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def is_potential_nosetest(item: Item) -> bool:
    # extra check needed since we do not do nose style setup/teardown
    # on direct unittest style classes
    return isinstance(item, python.Function) and not isinstance(
        item, unittest.TestCaseFunction
    ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:8,代码来源:nose.py

示例7: _add_item_hier_parts_other

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [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

示例8: _get_item_description

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [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

示例9: _add_xfail_markers

# 需要导入模块: from _pytest import python [as 别名]
# 或者: from _pytest.python import Function [as 别名]
def _add_xfail_markers(item: Function) -> None:
    """
    Mute flaky Integration Tests with custom pytest marker.
    Rationale for doing this is mentioned at DCOS-45308.
    """
    xfailflake_markers = [
        marker for marker in item.iter_markers() if marker.name == 'xfailflake'
    ]
    for xfailflake_marker in xfailflake_markers:
        assert 'reason' in xfailflake_marker.kwargs
        assert 'jira' in xfailflake_marker.kwargs
        assert xfailflake_marker.kwargs['jira'].startswith('DCOS')
        # Show the JIRA in the printed reason.
        xfailflake_marker.kwargs['reason'] = '{jira} - {reason}'.format(
            jira=xfailflake_marker.kwargs['jira'],
            reason=xfailflake_marker.kwargs['reason'],
        )
        date_text = xfailflake_marker.kwargs['since']
        try:
            datetime.datetime.strptime(date_text, '%Y-%m-%d')
        except ValueError:
            message = (
                'Incorrect date format for "since", should be YYYY-MM-DD'
            )
            raise ValueError(message)

        # The marker is not "strict" unless that is explicitly stated.
        # That means that by default, no error is raised if the test passes or
        # fails.
        strict = xfailflake_marker.kwargs.get('strict', False)
        xfailflake_marker.kwargs['strict'] = strict
        xfail_marker = pytest.mark.xfail(
            *xfailflake_marker.args,
            **xfailflake_marker.kwargs,
        )
        item.add_marker(xfail_marker) 
开发者ID:dcos,项目名称:dcos-e2e,代码行数:38,代码来源:plugin.py


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