Skip to content

Commit 7862517

Browse files
authored
Merge pull request #1760 from blueyed/followup-pr1718-remove-newline
Followup to #1718: style/formatting
2 parents 9891593 + 5c5d7e0 commit 7862517

File tree

4 files changed

+48
-66
lines changed

4 files changed

+48
-66
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ time or change existing behaviors in order to make them less surprising/more use
123123

124124
Thanks `@d6e`_, `@kvas-it`_, `@sallner`_ and `@omarkohl`_ for the PRs.
125125

126-
* New cli flag ``--override-ini``/``-o``: overrides values from the ini file.
126+
* New CLI flag ``--override-ini``/``-o``: overrides values from the ini file.
127127
For example: ``"-o xfail_strict=True"``'.
128128
Thanks `@blueyed`_ and `@fengxx`_ for the PR.
129129

_pytest/helpconfig.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def pytest_addoption(parser):
2020
group.addoption('--debug',
2121
action="store_true", dest="debug", default=False,
2222
help="store internal tracing debug information in 'pytestdebug.log'.")
23-
# support for "--overwrite-ini ININAME=INIVALUE" to override values from the ini file
24-
# Example '-o xfail_strict=True'.
25-
group._addoption('-o', '--override-ini', nargs='*', dest="override_ini", action="append",
26-
help="overrides ini values which do not have a separate command-line flag")
23+
group._addoption(
24+
'-o', '--override-ini', nargs='*', dest="override_ini",
25+
action="append",
26+
help="override config option, e.g. `-o xfail_strict=True`.")
2727

2828

2929
@pytest.hookimpl(hookwrapper=True)

testing/python/fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ def finalize():
21802180
return {}
21812181
""")
21822182
b = testdir.mkdir("subdir")
2183-
b.join("test_overriden_fixture_finalizer.py").write(dedent("""
2183+
b.join("test_overridden_fixture_finalizer.py").write(dedent("""
21842184
import pytest
21852185
@pytest.fixture
21862186
def browser(browser):

testing/test_config.py

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -616,90 +616,72 @@ def test_with_specific_inifile(self, tmpdir):
616616
assert rootdir == tmpdir
617617

618618
class TestOverrideIniArgs:
619-
""" test --override-ini """
620619
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
621620
def test_override_ini_names(self, testdir, name):
622621
testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""
623622
[pytest]
624-
custom = 1.0
625-
"""))
623+
custom = 1.0"""))
626624
testdir.makeconftest("""
627625
def pytest_addoption(parser):
628-
parser.addini("custom", "")
629-
""")
626+
parser.addini("custom", "")""")
630627
testdir.makepyfile("""
631628
def test_pass(pytestconfig):
632629
ini_val = pytestconfig.getini("custom")
633-
print('\\ncustom_option:%s\\n' % ini_val)
634-
""")
630+
print('\\ncustom_option:%s\\n' % ini_val)""")
635631

636632
result = testdir.runpytest("--override-ini", "custom=2.0", "-s")
637633
assert result.ret == 0
638-
result.stdout.fnmatch_lines([
639-
"custom_option:2.0"
640-
])
634+
result.stdout.fnmatch_lines(["custom_option:2.0"])
641635

642636
result = testdir.runpytest("--override-ini", "custom=2.0",
643637
"--override-ini=custom=3.0", "-s")
644638
assert result.ret == 0
645-
result.stdout.fnmatch_lines([
646-
"custom_option:3.0"
647-
])
639+
result.stdout.fnmatch_lines(["custom_option:3.0"])
648640

649641

650642
def test_override_ini_pathlist(self, testdir):
651643
testdir.makeconftest("""
652-
def pytest_addoption(parser):
653-
parser.addini("paths", "my new ini value", type="pathlist")
654-
""")
644+
def pytest_addoption(parser):
645+
parser.addini("paths", "my new ini value", type="pathlist")""")
655646
testdir.makeini("""
656-
[pytest]
657-
paths=blah.py
658-
""")
647+
[pytest]
648+
paths=blah.py""")
659649
testdir.makepyfile("""
660-
import py.path
661-
def test_pathlist(pytestconfig):
662-
config_paths = pytestconfig.getini("paths")
663-
print(config_paths)
664-
for cpf in config_paths:
665-
print('\\nuser_path:%s' % cpf.basename)
666-
""")
667-
result = testdir.runpytest("--override-ini", 'paths=foo/bar1.py foo/bar2.py', "-s")
668-
result.stdout.fnmatch_lines([
669-
"user_path:bar1.py",
670-
"user_path:bar2.py"
671-
])
650+
import py.path
651+
def test_pathlist(pytestconfig):
652+
config_paths = pytestconfig.getini("paths")
653+
print(config_paths)
654+
for cpf in config_paths:
655+
print('\\nuser_path:%s' % cpf.basename)""")
656+
result = testdir.runpytest("--override-ini",
657+
'paths=foo/bar1.py foo/bar2.py', "-s")
658+
result.stdout.fnmatch_lines(["user_path:bar1.py",
659+
"user_path:bar2.py"])
672660

673661
def test_override_multiple_and_default(self, testdir):
674662
testdir.makeconftest("""
675-
def pytest_addoption(parser):
676-
parser.addini("custom_option_1", "", default="o1")
677-
parser.addini("custom_option_2", "", default="o2")
678-
parser.addini("custom_option_3", "", default=False, type="bool")
679-
parser.addini("custom_option_4", "", default=True, type="bool")
680-
681-
""")
663+
def pytest_addoption(parser):
664+
addini = parser.addini
665+
addini("custom_option_1", "", default="o1")
666+
addini("custom_option_2", "", default="o2")
667+
addini("custom_option_3", "", default=False, type="bool")
668+
addini("custom_option_4", "", default=True, type="bool")""")
682669
testdir.makeini("""
683-
[pytest]
684-
custom_option_1=custom_option_1
685-
custom_option_2=custom_option_2
686-
""")
670+
[pytest]
671+
custom_option_1=custom_option_1
672+
custom_option_2=custom_option_2""")
687673
testdir.makepyfile("""
688-
def test_multiple_options(pytestconfig):
689-
prefix="custom_option"
690-
for x in range(1,5):
691-
ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
692-
print('\\nini%d:%s' % (x, ini_value))
693-
""")
694-
result = testdir.runpytest("--override-ini",
695-
'custom_option_1=fulldir=/tmp/user1',
696-
'custom_option_2=url=/tmp/user2?a=b&d=e',
697-
"-o", 'custom_option_3=True',
698-
"-o", 'custom_option_4=no',
699-
"-s")
700-
result.stdout.fnmatch_lines([
701-
"ini1:fulldir=/tmp/user1",
702-
"ini2:url=/tmp/user2?a=b&d=e",
703-
"ini3:True",
704-
"ini4:False"
705-
])
674+
def test_multiple_options(pytestconfig):
675+
prefix = "custom_option"
676+
for x in range(1, 5):
677+
ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
678+
print('\\nini%d:%s' % (x, ini_value))""")
679+
result = testdir.runpytest(
680+
"--override-ini", 'custom_option_1=fulldir=/tmp/user1',
681+
'custom_option_2=url=/tmp/user2?a=b&d=e',
682+
"-o", 'custom_option_3=True',
683+
"-o", 'custom_option_4=no', "-s")
684+
result.stdout.fnmatch_lines(["ini1:fulldir=/tmp/user1",
685+
"ini2:url=/tmp/user2?a=b&d=e",
686+
"ini3:True",
687+
"ini4:False"])

0 commit comments

Comments
 (0)