Followup to #1718: style/formatting
This commit is contained in:
parent
9891593413
commit
5c5d7e05f7
|
@ -123,7 +123,7 @@ time or change existing behaviors in order to make them less surprising/more use
|
||||||
|
|
||||||
Thanks `@d6e`_, `@kvas-it`_, `@sallner`_ and `@omarkohl`_ for the PRs.
|
Thanks `@d6e`_, `@kvas-it`_, `@sallner`_ and `@omarkohl`_ for the PRs.
|
||||||
|
|
||||||
* New cli flag ``--override-ini``/``-o``: overrides values from the ini file.
|
* New CLI flag ``--override-ini``/``-o``: overrides values from the ini file.
|
||||||
For example: ``"-o xfail_strict=True"``'.
|
For example: ``"-o xfail_strict=True"``'.
|
||||||
Thanks `@blueyed`_ and `@fengxx`_ for the PR.
|
Thanks `@blueyed`_ and `@fengxx`_ for the PR.
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ def pytest_addoption(parser):
|
||||||
group.addoption('--debug',
|
group.addoption('--debug',
|
||||||
action="store_true", dest="debug", default=False,
|
action="store_true", dest="debug", default=False,
|
||||||
help="store internal tracing debug information in 'pytestdebug.log'.")
|
help="store internal tracing debug information in 'pytestdebug.log'.")
|
||||||
# support for "--overwrite-ini ININAME=INIVALUE" to override values from the ini file
|
group._addoption(
|
||||||
# Example '-o xfail_strict=True'.
|
'-o', '--override-ini', nargs='*', dest="override_ini",
|
||||||
group._addoption('-o', '--override-ini', nargs='*', dest="override_ini", action="append",
|
action="append",
|
||||||
help="overrides ini values which do not have a separate command-line flag")
|
help="override config option, e.g. `-o xfail_strict=True`.")
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(hookwrapper=True)
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
|
|
@ -2180,7 +2180,7 @@ class TestFixtureMarker:
|
||||||
return {}
|
return {}
|
||||||
""")
|
""")
|
||||||
b = testdir.mkdir("subdir")
|
b = testdir.mkdir("subdir")
|
||||||
b.join("test_overriden_fixture_finalizer.py").write(dedent("""
|
b.join("test_overridden_fixture_finalizer.py").write(dedent("""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def browser(browser):
|
def browser(browser):
|
||||||
|
|
|
@ -616,90 +616,72 @@ class TestRootdir:
|
||||||
assert rootdir == tmpdir
|
assert rootdir == tmpdir
|
||||||
|
|
||||||
class TestOverrideIniArgs:
|
class TestOverrideIniArgs:
|
||||||
""" test --override-ini """
|
|
||||||
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
||||||
def test_override_ini_names(self, testdir, name):
|
def test_override_ini_names(self, testdir, name):
|
||||||
testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
custom = 1.0
|
custom = 1.0"""))
|
||||||
"""))
|
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addini("custom", "")
|
parser.addini("custom", "")""")
|
||||||
""")
|
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
def test_pass(pytestconfig):
|
def test_pass(pytestconfig):
|
||||||
ini_val = pytestconfig.getini("custom")
|
ini_val = pytestconfig.getini("custom")
|
||||||
print('\\ncustom_option:%s\\n' % ini_val)
|
print('\\ncustom_option:%s\\n' % ini_val)""")
|
||||||
""")
|
|
||||||
|
|
||||||
result = testdir.runpytest("--override-ini", "custom=2.0", "-s")
|
result = testdir.runpytest("--override-ini", "custom=2.0", "-s")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines(["custom_option:2.0"])
|
||||||
"custom_option:2.0"
|
|
||||||
])
|
|
||||||
|
|
||||||
result = testdir.runpytest("--override-ini", "custom=2.0",
|
result = testdir.runpytest("--override-ini", "custom=2.0",
|
||||||
"--override-ini=custom=3.0", "-s")
|
"--override-ini=custom=3.0", "-s")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines(["custom_option:3.0"])
|
||||||
"custom_option:3.0"
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def test_override_ini_pathlist(self, testdir):
|
def test_override_ini_pathlist(self, testdir):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addini("paths", "my new ini value", type="pathlist")
|
parser.addini("paths", "my new ini value", type="pathlist")""")
|
||||||
""")
|
|
||||||
testdir.makeini("""
|
testdir.makeini("""
|
||||||
[pytest]
|
[pytest]
|
||||||
paths=blah.py
|
paths=blah.py""")
|
||||||
""")
|
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import py.path
|
import py.path
|
||||||
def test_pathlist(pytestconfig):
|
def test_pathlist(pytestconfig):
|
||||||
config_paths = pytestconfig.getini("paths")
|
config_paths = pytestconfig.getini("paths")
|
||||||
print(config_paths)
|
print(config_paths)
|
||||||
for cpf in config_paths:
|
for cpf in config_paths:
|
||||||
print('\\nuser_path:%s' % cpf.basename)
|
print('\\nuser_path:%s' % cpf.basename)""")
|
||||||
""")
|
result = testdir.runpytest("--override-ini",
|
||||||
result = testdir.runpytest("--override-ini", 'paths=foo/bar1.py foo/bar2.py', "-s")
|
'paths=foo/bar1.py foo/bar2.py', "-s")
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines(["user_path:bar1.py",
|
||||||
"user_path:bar1.py",
|
"user_path:bar2.py"])
|
||||||
"user_path:bar2.py"
|
|
||||||
])
|
|
||||||
|
|
||||||
def test_override_multiple_and_default(self, testdir):
|
def test_override_multiple_and_default(self, testdir):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addini("custom_option_1", "", default="o1")
|
addini = parser.addini
|
||||||
parser.addini("custom_option_2", "", default="o2")
|
addini("custom_option_1", "", default="o1")
|
||||||
parser.addini("custom_option_3", "", default=False, type="bool")
|
addini("custom_option_2", "", default="o2")
|
||||||
parser.addini("custom_option_4", "", default=True, type="bool")
|
addini("custom_option_3", "", default=False, type="bool")
|
||||||
|
addini("custom_option_4", "", default=True, type="bool")""")
|
||||||
""")
|
|
||||||
testdir.makeini("""
|
testdir.makeini("""
|
||||||
[pytest]
|
[pytest]
|
||||||
custom_option_1=custom_option_1
|
custom_option_1=custom_option_1
|
||||||
custom_option_2=custom_option_2
|
custom_option_2=custom_option_2""")
|
||||||
""")
|
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
def test_multiple_options(pytestconfig):
|
def test_multiple_options(pytestconfig):
|
||||||
prefix="custom_option"
|
prefix = "custom_option"
|
||||||
for x in range(1,5):
|
for x in range(1, 5):
|
||||||
ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
|
ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
|
||||||
print('\\nini%d:%s' % (x, ini_value))
|
print('\\nini%d:%s' % (x, ini_value))""")
|
||||||
""")
|
result = testdir.runpytest(
|
||||||
result = testdir.runpytest("--override-ini",
|
"--override-ini", 'custom_option_1=fulldir=/tmp/user1',
|
||||||
'custom_option_1=fulldir=/tmp/user1',
|
'custom_option_2=url=/tmp/user2?a=b&d=e',
|
||||||
'custom_option_2=url=/tmp/user2?a=b&d=e',
|
"-o", 'custom_option_3=True',
|
||||||
"-o", 'custom_option_3=True',
|
"-o", 'custom_option_4=no', "-s")
|
||||||
"-o", 'custom_option_4=no',
|
result.stdout.fnmatch_lines(["ini1:fulldir=/tmp/user1",
|
||||||
"-s")
|
"ini2:url=/tmp/user2?a=b&d=e",
|
||||||
result.stdout.fnmatch_lines([
|
"ini3:True",
|
||||||
"ini1:fulldir=/tmp/user1",
|
"ini4:False"])
|
||||||
"ini2:url=/tmp/user2?a=b&d=e",
|
|
||||||
"ini3:True",
|
|
||||||
"ini4:False"
|
|
||||||
])
|
|
||||||
|
|
Loading…
Reference in New Issue