本文整理匯總了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
示例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"
示例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")
示例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")
示例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
示例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
示例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"])
示例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*"])
示例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
示例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"
)
示例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
示例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()
示例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) == {}
示例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"}
示例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"}