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