-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --overwrite-ini ININAME=INIVALUE cli option #1667
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,3 +583,92 @@ def test_with_specific_inifile(self, tmpdir): | |
inifile = tmpdir.ensure("pytest.ini") | ||
rootdir, inifile, inicfg = determine_setup(inifile, [tmpdir]) | ||
assert rootdir == tmpdir | ||
|
||
class TestOverrideIniArgs: | ||
""" test --override-ini """ | ||
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split()) | ||
def test_override_ini_names(self, testdir, name): | ||
testdir.tmpdir.join(name).write(py.std.textwrap.dedent(""" | ||
[pytest] | ||
custom = 1.0 | ||
""")) | ||
testdir.makeconftest(""" | ||
def pytest_addoption(parser): | ||
parser.addini("custom", "") | ||
""") | ||
testdir.makepyfile(""" | ||
def test_pass(pytestconfig): | ||
ini_val = pytestconfig.getini("custom") | ||
print('\\ncustom_option:%s\\n' % ini_val) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad style because of using global state: better just accept |
||
""") | ||
|
||
result = testdir.runpytest("--override-ini", "custom=2.0", "-s") | ||
assert result.ret == 0 | ||
result.stdout.fnmatch_lines([ | ||
"custom_option:2.0" | ||
]) | ||
|
||
result = testdir.runpytest("--override-ini", "custom=2.0", | ||
"--override-ini=custom=3.0", "-s") | ||
assert result.ret == 0 | ||
result.stdout.fnmatch_lines([ | ||
"custom_option:3.0" | ||
]) | ||
|
||
|
||
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" | ||
]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test which sets two different options (say, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
def test_override_multiple_and_default(self, testdir): | ||
testdir.makeconftest(""" | ||
def pytest_addoption(parser): | ||
parser.addini("custom_option_1", "", default="o1") | ||
parser.addini("custom_option_2", "", default="o2") | ||
parser.addini("custom_option_3", "", default=False, type="bool") | ||
parser.addini("custom_option_4", "", default=True, type="bool") | ||
|
||
""") | ||
testdir.makeini(""" | ||
[pytest] | ||
custom_option_1=custom_option_1 | ||
custom_option_2=custom_option_2 | ||
""") | ||
testdir.makepyfile(""" | ||
def test_multiple_options(pytestconfig): | ||
prefix="custom_option" | ||
for x in range(1,5): | ||
ini_value=pytestconfig.getini("%s_%d" % (prefix, x)) | ||
print('\\nini%d:%s' % (x, ini_value)) | ||
""") | ||
result = testdir.runpytest("--override-ini", | ||
'custom_option_1=fulldir=/tmp/user1', | ||
'custom_option_2=url=/tmp/user2?a=b&d=e', | ||
"-o", 'custom_option_3=True', | ||
"-o", 'custom_option_4=no', | ||
"-s") | ||
result.stdout.fnmatch_lines([ | ||
"ini1:fulldir=/tmp/user1", | ||
"ini2:url=/tmp/user2?a=b&d=e", | ||
"ini3:True", | ||
"ini4:False" | ||
]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we also need a test for multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrited the testcase to use multiple -o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply
return None
here and remove thevalue = None
above?