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


Python pytest.File方法代码示例

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


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

示例1: test_getcustomfile_roundtrip

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_getcustomfile_roundtrip(self, testdir):
        hello = testdir.makefile(".xxx", hello="world")
        testdir.makepyfile(
            conftest="""
            import pytest
            class CustomFile(pytest.File):
                pass
            def pytest_collect_file(path, parent):
                if path.ext == ".xxx":
                    return CustomFile.from_parent(fspath=path, parent=parent)
        """
        )
        node = testdir.getpathnode(hello)
        assert isinstance(node, pytest.File)
        assert node.name == "hello.xxx"
        nodes = node.session.perform_collect([node.nodeid], genitems=False)
        assert len(nodes) == 1
        assert isinstance(nodes[0], pytest.File) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:test_collection.py

示例2: test_custom_repr_failure

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_custom_repr_failure(self, testdir):
        p = testdir.makepyfile(
            """
            import not_exists
        """
        )
        testdir.makeconftest(
            """
            import pytest
            def pytest_collect_file(path, parent):
                return MyFile(path, parent)
            class MyError(Exception):
                pass
            class MyFile(pytest.File):
                def collect(self):
                    raise MyError()
                def repr_failure(self, excinfo):
                    if excinfo.errisinstance(MyError):
                        return "hello world"
                    return pytest.File.repr_failure(self, excinfo)
        """
        )

        result = testdir.runpytest(p)
        result.stdout.fnmatch_lines(["*ERROR collecting*", "*hello world*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:27,代码来源:test_collection.py

示例3: test_fscollector_from_parent

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_fscollector_from_parent(tmpdir, request):
    """Ensure File.from_parent can forward custom arguments to the constructor.

    Context: https://github.com/pytest-dev/pytest-cpp/pull/47
    """

    class MyCollector(pytest.File):
        def __init__(self, fspath, parent, x):
            super().__init__(fspath, parent)
            self.x = x

        @classmethod
        def from_parent(cls, parent, *, fspath, x):
            return super().from_parent(parent=parent, fspath=fspath, x=x)

    collector = MyCollector.from_parent(
        parent=request.session, fspath=tmpdir / "foo", x=10
    )
    assert collector.x == 10 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:test_collection.py

示例4: dummy_yaml_custom_test

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def dummy_yaml_custom_test(testdir):
    """Writes a conftest file that collects and executes a dummy yaml test.

    Taken from the docs, but stripped down to the bare minimum, useful for
    tests which needs custom items collected.
    """
    testdir.makeconftest(
        """
        import pytest

        def pytest_collect_file(parent, path):
            if path.ext == ".yaml" and path.basename.startswith("test"):
                return YamlFile(path, parent)

        class YamlFile(pytest.File):
            def collect(self):
                yield YamlItem(self.fspath.basename, self)

        class YamlItem(pytest.Item):
            def runtest(self):
                pass
    """
    )
    testdir.makefile(".yaml", test1="") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:conftest.py

示例5: test_failure_issue380

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_failure_issue380(testdir):
    testdir.makeconftest(
        """
        import pytest
        class MyCollector(pytest.File):
            def collect(self):
                raise ValueError()
            def repr_failure(self, excinfo):
                return "somestring"
        def pytest_collect_file(path, parent):
            return MyCollector(parent=parent, fspath=path)
    """
    )
    testdir.makepyfile(
        """
        def test_func():
            pass
    """
    )
    result = testdir.runpytest("--resultlog=log")
    assert result.ret == 2 
开发者ID:pytest-dev,项目名称:pytest,代码行数:23,代码来源:test_resultlog.py

示例6: test_early_hook_error_issue38_1

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_early_hook_error_issue38_1(self, testdir):
        testdir.makeconftest(
            """
            def pytest_sessionstart():
                0 / 0
        """
        )
        result = testdir.runpytest(testdir.tmpdir)
        assert result.ret != 0
        # tracestyle is native by default for hook failures
        result.stdout.fnmatch_lines(
            ["*INTERNALERROR*File*conftest.py*line 2*", "*0 / 0*"]
        )
        result = testdir.runpytest(testdir.tmpdir, "--fulltrace")
        assert result.ret != 0
        # tracestyle is native by default for hook failures
        result.stdout.fnmatch_lines(
            ["*INTERNALERROR*def pytest_sessionstart():*", "*INTERNALERROR*0 / 0*"]
        ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:acceptance_test.py

示例7: test_multiple_items_per_collector_byid

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_multiple_items_per_collector_byid(self, testdir):
        c = testdir.makeconftest(
            """
            import pytest
            class MyItem(pytest.Item):
                def runtest(self):
                    pass
            class MyCollector(pytest.File):
                def collect(self):
                    return [MyItem(name="xyz", parent=self)]
            def pytest_collect_file(path, parent):
                if path.basename.startswith("conftest"):
                    return MyCollector(path, parent)
        """
        )
        result = testdir.runpytest(c.basename + "::" + "xyz")
        assert result.ret == 0
        result.stdout.fnmatch_lines(["*1 pass*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:acceptance_test.py

示例8: pytest_make_collect_report

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def pytest_make_collect_report(self, collector):
        if isinstance(collector, pytest.File):
            self.resume_global_capture()
            outcome = yield
            self.suspend_global_capture()
            out, err = self.read_global_capture()
            rep = outcome.get_result()
            if out:
                rep.sections.append(("Captured stdout", out))
            if err:
                rep.sections.append(("Captured stderr", err))
        else:
            yield 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:15,代码来源:capture.py

示例9: pytest_make_collect_report

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def pytest_make_collect_report(self, collector: Collector):
        if isinstance(collector, pytest.File):
            self.resume_global_capture()
            outcome = yield
            self.suspend_global_capture()
            out, err = self.read_global_capture()
            rep = outcome.get_result()
            if out:
                rep.sections.append(("Captured stdout", out))
            if err:
                rep.sections.append(("Captured stderr", err))
        else:
            yield 
开发者ID:pytest-dev,项目名称:pytest,代码行数:15,代码来源:capture.py

示例10: test_collect_custom_nodes_multi_id

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_collect_custom_nodes_multi_id(self, testdir):
        p = testdir.makepyfile("def test_func(): pass")
        testdir.makeconftest(
            """
            import pytest
            class SpecialItem(pytest.Item):
                def runtest(self):
                    return # ok
            class SpecialFile(pytest.File):
                def collect(self):
                    return [SpecialItem(name="check", parent=self)]
            def pytest_collect_file(path, parent):
                if path.basename == %r:
                    return SpecialFile(fspath=path, parent=parent)
        """
            % p.basename
        )
        id = p.basename

        items, hookrec = testdir.inline_genitems(id)
        pprint.pprint(hookrec.calls)
        assert len(items) == 2
        hookrec.assert_contains(
            [
                ("pytest_collectstart", "collector.fspath == collector.session.fspath"),
                (
                    "pytest_collectstart",
                    "collector.__class__.__name__ == 'SpecialFile'",
                ),
                ("pytest_collectstart", "collector.__class__.__name__ == 'Module'"),
                ("pytest_pycollect_makeitem", "name == 'test_func'"),
                ("pytest_collectreport", "report.nodeid.startswith(p.basename)"),
            ]
        )
        assert len(self.get_reported_items(hookrec)) == 2 
开发者ID:pytest-dev,项目名称:pytest,代码行数:37,代码来源:test_collection.py

示例11: test_matchnodes_two_collections_same_file

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_matchnodes_two_collections_same_file(testdir):
    testdir.makeconftest(
        """
        import pytest
        def pytest_configure(config):
            config.pluginmanager.register(Plugin2())

        class Plugin2(object):
            def pytest_collect_file(self, path, parent):
                if path.ext == ".abc":
                    return MyFile2(path, parent)

        def pytest_collect_file(path, parent):
            if path.ext == ".abc":
                return MyFile1(path, parent)

        class MyFile1(pytest.Item, pytest.File):
            def runtest(self):
                pass
        class MyFile2(pytest.File):
            def collect(self):
                return [Item2("hello", parent=self)]

        class Item2(pytest.Item):
            def runtest(self):
                pass
    """
    )
    p = testdir.makefile(".abc", "")
    result = testdir.runpytest()
    assert result.ret == 0
    result.stdout.fnmatch_lines(["*2 passed*"])
    res = testdir.runpytest("%s::hello" % p.basename)
    res.stdout.fnmatch_lines(["*1 passed*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:36,代码来源:test_collection.py

示例12: test_import_star_pytest

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_import_star_pytest(self, testdir):
        p = testdir.makepyfile(
            """
            from pytest import *
            #Item
            #File
            main
            skip
            xfail
        """
        )
        result = testdir.runpython(p)
        assert result.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:15,代码来源:acceptance_test.py

示例13: test00_get_type_string

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test00_get_type_string():
    assert get_type_string([]) == 'ARRAY'
    assert get_type_string({}) == 'OBJECT'
    assert get_type_string({'a': []}) == 'OBJECT'
    assert get_type_string(None) == 'null'
    assert get_type_string(1.5) == 'float'
    assert get_type_string(set()) == 'unknown'
    assert get_type_string(pytest.File) == 'unknown' 
开发者ID:pajachiet,项目名称:pymongo-schema,代码行数:10,代码来源:test_mongo_sql_types.py

示例14: collect

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def collect(self):
        """Create a PyLintItem for the File."""
        yield PyLintItem.from_parent(
            parent=self,
            name='{}::PYLINT'.format(self.fspath)
        ) 
开发者ID:carsongee,项目名称:pytest-pylint,代码行数:8,代码来源:plugin.py

示例15: test_fancy_items_regression

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import File [as 别名]
def test_fancy_items_regression(testdir, run_and_parse):
    # issue 1259
    testdir.makeconftest(
        """
        import pytest
        class FunItem(pytest.Item):
            def runtest(self):
                pass
        class NoFunItem(pytest.Item):
            def runtest(self):
                pass

        class FunCollector(pytest.File):
            def collect(self):
                return [
                    FunItem('a', self),
                    NoFunItem('a', self),
                    NoFunItem('b', self),
                ]

        def pytest_collect_file(path, parent):
            if path.check(ext='.py'):
                return FunCollector(path, parent)
    """
    )

    testdir.makepyfile(
        """
        def test_pass():
            pass
    """
    )

    result, dom = run_and_parse()

    result.stdout.no_fnmatch_line("*INTERNALERROR*")

    items = sorted("%(classname)s %(name)s" % x for x in dom.find_by_tag("testcase"))
    import pprint

    pprint.pprint(items)
    assert items == [
        "conftest a",
        "conftest a",
        "conftest b",
        "test_fancy_items_regression a",
        "test_fancy_items_regression a",
        "test_fancy_items_regression b",
        "test_fancy_items_regression test_pass",
    ] 
开发者ID:pytest-dev,项目名称:pytest,代码行数:52,代码来源:test_junitxml.py


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