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


Python pytest.Function方法代码示例

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


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

示例1: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_runtest_setup(item):
    # here we seem to get called only based on what we collected
    # in pytest_collection_modifyitems.   So to do class-based stuff
    # we have to tear that out.
    global _current_class

    if not isinstance(item, pytest.Function):
        return

    # ... so we're doing a little dance here to figure it out...
    if _current_class is None:
        class_setup(item.parent.parent)
        _current_class = item.parent.parent

        # this is needed for the class-level, to ensure that the
        # teardown runs after the class is completed with its own
        # class-level teardown...
        def finalize():
            global _current_class
            class_teardown(item.parent.parent)
            _current_class = None
        item.parent.parent.addfinalizer(finalize)

    test_setup(item) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:pytestplugin.py

示例2: test_custom_failure_repr

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_custom_failure_repr(self, testdir) -> None:
        testdir.makepyfile(
            conftest="""
            import pytest
            class Function(pytest.Function):
                def repr_failure(self, excinfo):
                    return "hello"
        """
        )
        reports = testdir.runitem(
            """
            import pytest
            def test_func():
                assert 0
        """
        )
        rep = reports[1]
        assert not rep.skipped
        assert not rep.passed
        assert rep.failed
        # assert rep.outcome.when == "call"
        # assert rep.failed.where.lineno == 3
        # assert rep.failed.where.path.basename == "test_func.py"
        # assert rep.failed.failurerepr == "hello" 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:test_runner.py

示例3: test_getparent

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_getparent(self, testdir):
        modcol = testdir.getmodulecol(
            """
            class TestClass:
                 def test_foo(self):
                     pass
        """
        )
        cls = testdir.collect_by_name(modcol, "TestClass")
        fn = testdir.collect_by_name(testdir.collect_by_name(cls, "()"), "test_foo")

        parent = fn.getparent(pytest.Module)
        assert parent is modcol

        parent = fn.getparent(pytest.Function)
        assert parent is fn

        parent = fn.getparent(pytest.Class)
        assert parent is cls 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:test_collection.py

示例4: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_runtest_setup(item):
    # Conditionally skip tests that are pinned to a specific ansible version
    if isinstance(item, pytest.Function):
        # conditionally skip
        if item.get_closest_marker('requires_ansible_v1') and not has_ansible_v1:
            pytest.skip("requires < ansible-2.*")
        if item.get_closest_marker('requires_ansible_v2') and has_ansible_v1:
            pytest.skip("requires >= ansible-2.*")
        if item.get_closest_marker('requires_ansible_v24') and not has_ansible_v24:
            pytest.skip("requires >= ansible-2.4.*")
        if item.get_closest_marker('requires_ansible_v28') and not has_ansible_v24:
            pytest.skip("requires >= ansible-2.8.*")

        # conditionally xfail
        mark = item.get_closest_marker('ansible_v1_xfail')
        if mark and has_ansible_v1:
            item.add_marker(pytest.mark.xfail(reason="expected failure on < ansible-2.*",
                                              raises=mark.kwargs.get('raises')))

        mark = item.get_closest_marker('ansible_v2_xfail')
        if mark and not has_ansible_v1:
            item.add_marker(pytest.xfail(reason="expected failure on >= ansible-2.*",
                                         raises=mark.kwargs.get('raises'))) 
开发者ID:ansible,项目名称:pytest-ansible,代码行数:25,代码来源:conftest.py

示例5: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_runtest_setup(item):
    # here we seem to get called only based on what we collected
    # in pytest_collection_modifyitems.   So to do class-based stuff
    # we have to tear that out.
    global _current_class

    if not isinstance(item, pytest.Function):
        return

    # ... so we're doing a little dance here to figure it out...
    if item.parent.parent is not _current_class:

        class_setup(item.parent.parent)
        _current_class = item.parent.parent

        # this is needed for the class-level, to ensure that the
        # teardown runs after the class is completed with its own
        # class-level teardown...
        item.parent.parent.addfinalizer(
            lambda: class_teardown(item.parent.parent))

    test_setup(item) 
开发者ID:gltn,项目名称:stdm,代码行数:24,代码来源:pytestplugin.py

示例6: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_runtest_setup(item):
    # here we seem to get called only based on what we collected
    # in pytest_collection_modifyitems.   So to do class-based stuff
    # we have to tear that out.
    global _current_class

    if not isinstance(item, pytest.Function):
        return

    # ... so we're doing a little dance here to figure it out...
    if _current_class is None:
        class_setup(item.parent.parent)
        _current_class = item.parent.parent

        # this is needed for the class-level, to ensure that the
        # teardown runs after the class is completed with its own
        # class-level teardown...
        def finalize():
            global _current_class
            class_teardown(item.parent.parent)
            _current_class = None

        item.parent.parent.addfinalizer(finalize)

    test_setup(item) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:pytestplugin.py

示例7: pytest_runtest_setup

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_runtest_setup(item):
    # here we seem to get called only based on what we collected
    # in pytest_collection_modifyitems.   So to do class-based stuff
    # we have to tear that out.
    global _current_class

    if not isinstance(item, pytest.Function):
        return

    # ... so we're doing a little dance here to figure it out...
    if item.parent.parent is not _current_class:

        class_setup(item.parent.parent)
        _current_class = item.parent.parent

        # this is needed for the class-level, to ensure that the
        # teardown runs after the class is completed with its own
        # class-level teardown...
        item.parent.parent.addfinalizer(lambda: class_teardown(item.parent.parent))

    test_setup(item) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:23,代码来源:pytestplugin.py

示例8: test_failure_in_setup_function_ignores_custom_repr

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_failure_in_setup_function_ignores_custom_repr(self, testdir) -> None:
        testdir.makepyfile(
            conftest="""
            import pytest
            class Function(pytest.Function):
                def repr_failure(self, excinfo):
                    assert 0
        """
        )
        reports = testdir.runitem(
            """
            def setup_function(func):
                raise ValueError(42)
            def test_func():
                pass
        """
        )
        assert len(reports) == 2
        rep = reports[0]
        print(rep)
        assert not rep.skipped
        assert not rep.passed
        assert rep.failed
        # assert rep.outcome.when == "setup"
        # assert rep.outcome.where.lineno == 3
        # assert rep.outcome.where.path.basename == "test_func.py"
        # assert instanace(rep.failed.failurerepr, PythonFailureRepr) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:29,代码来源:test_runner.py

示例9: pytest_pycollect_makeitem

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_pycollect_makeitem(collector, name, obj):
    if inspect.isclass(obj) and plugin_base.want_class(obj):
        return pytest.Class(name, parent=collector)
    elif inspect.isfunction(obj) and \
            isinstance(collector, pytest.Instance) and \
            plugin_base.want_method(collector.cls, obj):
        return pytest.Function(name, parent=collector)
    else:
        return [] 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:pytestplugin.py

示例10: pytest_pycollect_makeitem

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def pytest_pycollect_makeitem(collector, name, obj):
    if collector.funcnamefilter(name):
        item = pytest.Function(name, parent=collector)
        if 'run_loop' in item.keywords:
            return list(collector._genfunctions(name, obj)) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:7,代码来源:conftest.py

示例11: test_check_equality

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_check_equality(self, testdir: Testdir) -> None:
        modcol = testdir.getmodulecol(
            """
            def test_pass(): pass
            def test_fail(): assert 0
        """
        )
        fn1 = testdir.collect_by_name(modcol, "test_pass")
        assert isinstance(fn1, pytest.Function)
        fn2 = testdir.collect_by_name(modcol, "test_pass")
        assert isinstance(fn2, pytest.Function)

        assert fn1 == fn2
        assert fn1 != modcol
        assert hash(fn1) == hash(fn2)

        fn3 = testdir.collect_by_name(modcol, "test_fail")
        assert isinstance(fn3, pytest.Function)
        assert not (fn1 == fn3)
        assert fn1 != fn3

        for fn in fn1, fn2, fn3:
            assert isinstance(fn, pytest.Function)
            assert fn != 3  # type: ignore[comparison-overlap]  # noqa: F821
            assert fn != modcol
            assert fn != [1, 2, 3]  # type: ignore[comparison-overlap]  # noqa: F821
            assert [1, 2, 3] != fn  # type: ignore[comparison-overlap]  # noqa: F821
            assert modcol != fn

        assert testdir.collect_by_name(modcol, "doesnotexist") is None 
开发者ID:pytest-dev,项目名称:pytest,代码行数:32,代码来源:test_collection.py

示例12: test_repr_produces_actual_test_id

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_repr_produces_actual_test_id(self, testdir):
        f = self.make_function(
            testdir, name=r"test[\xe5]", callobj=self.test_repr_produces_actual_test_id
        )
        assert repr(f) == r"<Function test[\xe5]>" 
开发者ID:pytest-dev,项目名称:pytest,代码行数:7,代码来源:collect.py

示例13: test_check_equality

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_check_equality(self, testdir) -> None:
        modcol = testdir.getmodulecol(
            """
            def test_pass(): pass
            def test_fail(): assert 0
        """
        )
        fn1 = testdir.collect_by_name(modcol, "test_pass")
        assert isinstance(fn1, pytest.Function)
        fn2 = testdir.collect_by_name(modcol, "test_pass")
        assert isinstance(fn2, pytest.Function)

        assert fn1 == fn2
        assert fn1 != modcol
        assert hash(fn1) == hash(fn2)

        fn3 = testdir.collect_by_name(modcol, "test_fail")
        assert isinstance(fn3, pytest.Function)
        assert not (fn1 == fn3)
        assert fn1 != fn3

        for fn in fn1, fn2, fn3:
            assert fn != 3  # type: ignore[comparison-overlap] # noqa: F821
            assert fn != modcol
            assert fn != [1, 2, 3]  # type: ignore[comparison-overlap] # noqa: F821
            assert [1, 2, 3] != fn  # type: ignore[comparison-overlap] # noqa: F821
            assert modcol != fn 
开发者ID:pytest-dev,项目名称:pytest,代码行数:29,代码来源:collect.py

示例14: test_pytest_pycollect_makeitem

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_pytest_pycollect_makeitem(self, testdir):
        testdir.makeconftest(
            """
            import pytest
            class MyFunction(pytest.Function):
                pass
            def pytest_pycollect_makeitem(collector, name, obj):
                if name == "some":
                    return MyFunction(name, collector)
        """
        )
        testdir.makepyfile("def some(): pass")
        result = testdir.runpytest("--collect-only")
        result.stdout.fnmatch_lines(["*MyFunction*some*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:16,代码来源:collect.py

示例15: test_itemreport_reportinfo

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import Function [as 别名]
def test_itemreport_reportinfo(self, testdir):
        testdir.makeconftest(
            """
            import pytest
            class MyFunction(pytest.Function):
                def reportinfo(self):
                    return "ABCDE", 42, "custom"
            def pytest_pycollect_makeitem(collector, name, obj):
                if name == "test_func":
                    return MyFunction.from_parent(name=name, parent=collector)
        """
        )
        item = testdir.getitem("def test_func(): pass")
        item.config.pluginmanager.getplugin("runner")
        assert item.location == ("ABCDE", 42, "custom") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:17,代码来源:collect.py


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