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


Python pytest.register_assert_rewrite方法代码示例

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


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

示例1: test_issue4445_rewrite

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def test_issue4445_rewrite(self, testdir, capwarn):
        """#4445: Make sure the warning points to a reasonable location
        See origin of _issue_warning_captured at: _pytest.assertion.rewrite.py:241
        """
        testdir.makepyfile(some_mod="")
        conftest = testdir.makeconftest(
            """
                import some_mod
                import pytest

                pytest.register_assert_rewrite("some_mod")
            """
        )
        testdir.parseconfig()

        # with stacklevel=5 the warning originates from register_assert_rewrite
        # function in the created conftest.py
        assert len(capwarn.captured) == 1
        warning, location = capwarn.captured.pop()
        file, lineno, func = location

        assert "Module already imported" in str(warning.message)
        assert file == str(conftest)
        assert func == "<module>"  # the above conftest.py
        assert lineno == 4 
开发者ID:pytest-dev,项目名称:pytest,代码行数:27,代码来源:test_warnings.py

示例2: assert_mypy_output

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def assert_mypy_output(pytestconfig):
    pytest.importorskip('mypy')  # we only install mypy in python>=3.6 tests
    pytest.register_assert_rewrite('tests.mypy_helpers')

    from tests.mypy_helpers import assert_mypy_output
    return lambda program: assert_mypy_output(program, use_pdb=pytestconfig.getoption('usepdb')) 
开发者ID:pynamodb,项目名称:PynamoDB,代码行数:8,代码来源:conftest.py

示例3: test_pdb_can_be_rewritten

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def test_pdb_can_be_rewritten(testdir):
    testdir.makepyfile(
        **{
            "conftest.py": """
                import pytest
                pytest.register_assert_rewrite("pdb")
                """,
            "__init__.py": "",
            "pdb.py": """
                def check():
                    assert 1 == 2
                """,
            "test_pdb.py": """
                def test():
                    import pdb
                    assert pdb.check()
                """,
        }
    )
    # Disable debugging plugin itself to avoid:
    # > INTERNALERROR> AttributeError: module 'pdb' has no attribute 'set_trace'
    result = testdir.runpytest_subprocess("-p", "no:debugging", "-vv")
    result.stdout.fnmatch_lines(
        [
            "    def check():",
            ">       assert 1 == 2",
            "E       assert 1 == 2",
            "E         +1",
            "E         -2",
            "",
            "pdb.py:2: AssertionError",
            "*= 1 failed in *",
        ]
    )
    assert result.ret == 1 
开发者ID:pytest-dev,项目名称:pytest,代码行数:37,代码来源:acceptance_test.py

示例4: test_register_assert_rewrite_checks_types

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def test_register_assert_rewrite_checks_types(self) -> None:
        with pytest.raises(TypeError):
            pytest.register_assert_rewrite(["pytest_tests_internal_non_existing"])  # type: ignore
        pytest.register_assert_rewrite(
            "pytest_tests_internal_non_existing", "pytest_tests_internal_non_existing2"
        ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:8,代码来源:test_assertion.py

示例5: test_rewrite_warning

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def test_rewrite_warning(self, testdir):
        testdir.makeconftest(
            """
            import pytest
            pytest.register_assert_rewrite("_pytest")
        """
        )
        # needs to be a subprocess because pytester explicitly disables this warning
        result = testdir.runpytest_subprocess()
        result.stdout.fnmatch_lines(["*Module already imported*: _pytest"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:12,代码来源:test_assertrewrite.py

示例6: test_rewrite_ast

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import register_assert_rewrite [as 别名]
def test_rewrite_ast(self, testdir):
        testdir.tmpdir.join("pkg").ensure(dir=1)
        contents = {
            "pkg/__init__.py": """
                import pytest
                pytest.register_assert_rewrite('pkg.helper')
            """,
            "pkg/helper.py": """
                def tool():
                    a, b = 2, 3
                    assert a == b
            """,
            "pkg/plugin.py": """
                import pytest, pkg.helper
                @pytest.fixture
                def tool():
                    return pkg.helper.tool
            """,
            "pkg/other.py": """
                values = [3, 2]
                def tool():
                    assert values.pop() == 3
            """,
            "conftest.py": """
                pytest_plugins = ['pkg.plugin']
            """,
            "test_pkg.py": """
                import pkg.other
                def test_tool(tool):
                    tool()
                def test_other():
                    pkg.other.tool()
            """,
        }
        testdir.makepyfile(**contents)
        result = testdir.runpytest_subprocess("--assert=rewrite")
        result.stdout.fnmatch_lines(
            [
                ">*assert a == b*",
                "E*assert 2 == 3*",
                ">*assert values.pop() == 3*",
                "E*AssertionError",
            ]
        ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:46,代码来源:test_assertion.py


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