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


Python pytest.ini方法代码示例

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


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

示例1: add_preconfigured_np

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def add_preconfigured_np(doctest_namespace):
    """
    Fixture executed for every doctest.

    Injects pre-configured numpy into each test's namespace.

    Note that even with this, doctests might fail due to the lack of full
    compatibility when using ``numpy.set_printoptions(legacy='1.13')``.

    Some of the whitespace issues can be fixed by ``NORMALIZE_WHITESPACE``
    doctest option, which is currently set in ``pytest.ini``.

    See: https://github.com/numpy/numpy/issues/10383
    """
    current_version = pkg_resources.parse_version(numpy.__version__)
    doctest_namespace['np'] = numpy 
开发者ID:fastats,项目名称:fastats,代码行数:18,代码来源:conftest.py

示例2: test_toxini_before_lower_pytestini

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_toxini_before_lower_pytestini(self, testdir):
        sub = testdir.tmpdir.mkdir("sub")
        sub.join("tox.ini").write(
            textwrap.dedent(
                """
            [pytest]
            minversion = 2.0
        """
            )
        )
        testdir.tmpdir.join("pytest.ini").write(
            textwrap.dedent(
                """
            [pytest]
            minversion = 1.5
        """
            )
        )
        config = testdir.parseconfigure(sub)
        assert config.getini("minversion") == "2.0" 
开发者ID:pytest-dev,项目名称:pytest,代码行数:22,代码来源:test_config.py

示例3: test_invalid_ini_keys

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_invalid_ini_keys(
        self, testdir, ini_file_text, invalid_keys, warning_output, exception_text
    ):
        testdir.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("conftest_ini_key", "")
        """
        )
        testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text))

        config = testdir.parseconfig()
        assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys)

        result = testdir.runpytest()
        result.stdout.fnmatch_lines(warning_output)

        if exception_text:
            with pytest.raises(pytest.fail.Exception, match=exception_text):
                testdir.runpytest("--strict-config")
        else:
            testdir.runpytest("--strict-config") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:24,代码来源:test_config.py

示例4: test_addini

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_addini(self, testdir):
        testdir.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("myname", "my new ini value")
        """
        )
        testdir.makeini(
            """
            [pytest]
            myname=hello
        """
        )
        config = testdir.parseconfig()
        val = config.getini("myname")
        assert val == "hello"
        pytest.raises(ValueError, config.getini, "other") 
开发者ID:pytest-dev,项目名称:pytest,代码行数:19,代码来源:test_config.py

示例5: test_addini_bool

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_addini_bool(self, testdir, str_val, bool_val):
        testdir.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("strip", "", type="bool", default=True)
        """
        )
        if str_val != "no-ini":
            testdir.makeini(
                """
                [pytest]
                strip=%s
            """
                % str_val
            )
        config = testdir.parseconfig()
        assert config.getini("strip") is bool_val 
开发者ID:pytest-dev,项目名称:pytest,代码行数:19,代码来源:test_config.py

示例6: test_config_in_subdirectory_colon_command_line_issue2148

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_config_in_subdirectory_colon_command_line_issue2148(testdir):
    conftest_source = """
        def pytest_addoption(parser):
            parser.addini('foo', 'foo')
    """

    testdir.makefile(
        ".ini",
        **{"pytest": "[pytest]\nfoo = root", "subdir/pytest": "[pytest]\nfoo = subdir"},
    )

    testdir.makepyfile(
        **{
            "conftest": conftest_source,
            "subdir/conftest": conftest_source,
            "subdir/test_foo": """\
            def test_foo(pytestconfig):
                assert pytestconfig.getini('foo') == 'subdir'
            """,
        }
    )

    result = testdir.runpytest("subdir/test_foo.py::test_foo")
    assert result.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:test_config.py

示例7: test_override_ini_pathlist

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_override_ini_pathlist(self, testdir):
        testdir.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("paths", "my new ini value", type="pathlist")"""
        )
        testdir.makeini(
            """
            [pytest]
            paths=blah.py"""
        )
        testdir.makepyfile(
            """
            import py.path
            def test_pathlist(pytestconfig):
                config_paths = pytestconfig.getini("paths")
                print(config_paths)
                for cpf in config_paths:
                    print('\\nuser_path:%s' % cpf.basename)"""
        )
        result = testdir.runpytest(
            "--override-ini", "paths=foo/bar1.py foo/bar2.py", "-s"
        )
        result.stdout.fnmatch_lines(["user_path:bar1.py", "user_path:bar2.py"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:test_config.py

示例8: test_override_ini_handled_asap

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_override_ini_handled_asap(self, testdir, with_ini):
        """-o should be handled as soon as possible and always override what's in ini files (#2238)"""
        if with_ini:
            testdir.makeini(
                """
                [pytest]
                python_files=test_*.py
            """
            )
        testdir.makepyfile(
            unittest_ini_handle="""
            def test():
                pass
        """
        )
        result = testdir.runpytest("--override-ini", "python_files=unittest_*.py")
        result.stdout.fnmatch_lines(["*1 passed in*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:19,代码来源:test_config.py

示例9: test_addopts_from_ini_not_concatenated

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_addopts_from_ini_not_concatenated(self, testdir):
        """addopts from ini should not take values from normal args (#4265)."""
        testdir.makeini(
            """
            [pytest]
            addopts=-o
        """
        )
        result = testdir.runpytest("cache_dir=ignored")
        result.stderr.fnmatch_lines(
            [
                "%s: error: argument -o/--override-ini: expected one argument (via addopts config)"
                % (testdir.request.config._parser.optparser.prog,)
            ]
        )
        assert result.ret == _pytest.config.ExitCode.USAGE_ERROR 
开发者ID:pytest-dev,项目名称:pytest,代码行数:18,代码来源:test_config.py

示例10: pytest_configure

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def pytest_configure(config):

    # Locally manage pytest.ini input
    for mark in ['io', 'bloch', 'hamiltonian', 'geometry', 'geom', 'shape',
                 'state', 'electron', 'phonon', 'utils', 'unit', 'distribution',
                 'spin', 'self_energy', 'help', 'messages', 'namedindex', 'sparse',
                 'supercell', 'sc', 'quaternion', 'sparse_geometry', 'ranges',
                 'orbital', 'oplist', 'grid', 'atoms', 'atom', 'sgrid', 'sdata', 'sgeom',
                 'version', 'bz', 'brillouinzone', 'inv', 'eig', 'linalg',
                 'density_matrix', 'dynamicalmatrix', 'energydensity_matrix',
                 'siesta', 'tbtrans', 'ham', 'vasp', 'w90', 'wannier90', 'gulp', 'fdf',
                 "category", "geom_category",
                 'table', 'cube', 'slow', 'selector', 'overlap', 'mixing']:
        config.addinivalue_line(
            "markers", f"{mark}: mark test to run only on named environment"
        ) 
开发者ID:zerothi,项目名称:sisl,代码行数:18,代码来源:conftest.py

示例11: bitcoin_regtest

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def bitcoin_regtest(docker, request):
    #logging.getLogger().setLevel(logging.DEBUG)
    requested_version = request.config.getoption("--bitcoind-version")
    if docker:
        bitcoind_controller = BitcoindDockerController(rpcport=18543, docker_tag=requested_version)
    else:
        if os.path.isfile('tests/bitcoin/src/bitcoind'):
            bitcoind_controller = BitcoindPlainController(bitcoind_path='tests/bitcoin/src/bitcoind') # always prefer the self-compiled bitcoind if existing
        else:
            bitcoind_controller = BitcoindPlainController() # Alternatively take the one on the path for now
    bitcoind_controller.start_bitcoind(cleanup_at_exit=True)
    running_version = bitcoind_controller.version()
    requested_version = request.config.getoption("--bitcoind-version")
    assert(running_version != requested_version, "Please make sure that the Bitcoind-version (%s) matches with the version in pytest.ini (%s)"%(running_version,requested_version))
    return bitcoind_controller 
开发者ID:cryptoadvance,项目名称:specter-desktop,代码行数:17,代码来源:conftest.py

示例12: option

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def option(self, pytestconfig):
        """
        fixture for ovewriting values in pytest.ini file

        :return: Option Object
        """

        new_value = {}

        class Options:
            @staticmethod
            def get(name):
                return new_value.get(name, pytestconfig.getini(name))

        return Options() 
开发者ID:mozilla,项目名称:iris,代码行数:17,代码来源:target.py

示例13: test_empty_pytest_ini

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_empty_pytest_ini(self, tmpdir):
        """pytest.ini files are always considered for configuration, even if empty"""
        fn = tmpdir.join("pytest.ini")
        fn.write("")
        assert load_config_dict_from_file(fn) == {} 
开发者ID:pytest-dev,项目名称:pytest,代码行数:7,代码来源:test_findpaths.py

示例14: test_pytest_ini

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_pytest_ini(self, tmpdir):
        """[pytest] section in pytest.ini files is read correctly"""
        fn = tmpdir.join("pytest.ini")
        fn.write("[pytest]\nx=1")
        assert load_config_dict_from_file(fn) == {"x": "1"} 
开发者ID:pytest-dev,项目名称:pytest,代码行数:7,代码来源:test_findpaths.py

示例15: test_custom_ini

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import ini [as 别名]
def test_custom_ini(self, tmpdir):
        """[pytest] section in any .ini file is read correctly"""
        fn = tmpdir.join("custom.ini")
        fn.write("[pytest]\nx=1")
        assert load_config_dict_from_file(fn) == {"x": "1"} 
开发者ID:pytest-dev,项目名称:pytest,代码行数:7,代码来源:test_findpaths.py


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