From 5c5d7e05f7406911cfbb91a4127032e90af68357 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 23 Jul 2016 18:09:42 +0200 Subject: [PATCH] Followup to #1718: style/formatting --- CHANGELOG.rst | 2 +- _pytest/helpconfig.py | 8 +-- testing/python/fixture.py | 2 +- testing/test_config.py | 102 ++++++++++++++++---------------------- 4 files changed, 48 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5f8ba271d..63b574e52 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. -* 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"``'. Thanks `@blueyed`_ and `@fengxx`_ for the PR. diff --git a/_pytest/helpconfig.py b/_pytest/helpconfig.py index ae8daea9c..f92ce1c04 100644 --- a/_pytest/helpconfig.py +++ b/_pytest/helpconfig.py @@ -20,10 +20,10 @@ def pytest_addoption(parser): group.addoption('--debug', action="store_true", dest="debug", default=False, help="store internal tracing debug information in 'pytestdebug.log'.") - # support for "--overwrite-ini ININAME=INIVALUE" to override values from the ini file - # Example '-o xfail_strict=True'. - group._addoption('-o', '--override-ini', nargs='*', dest="override_ini", action="append", - help="overrides ini values which do not have a separate command-line flag") + group._addoption( + '-o', '--override-ini', nargs='*', dest="override_ini", + action="append", + help="override config option, e.g. `-o xfail_strict=True`.") @pytest.hookimpl(hookwrapper=True) diff --git a/testing/python/fixture.py b/testing/python/fixture.py index e7232a25f..8870d76a7 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -2180,7 +2180,7 @@ class TestFixtureMarker: return {} """) b = testdir.mkdir("subdir") - b.join("test_overriden_fixture_finalizer.py").write(dedent(""" + b.join("test_overridden_fixture_finalizer.py").write(dedent(""" import pytest @pytest.fixture def browser(browser): diff --git a/testing/test_config.py b/testing/test_config.py index 12de364cc..54dac1bf7 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -616,90 +616,72 @@ class TestRootdir: 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 - """)) + custom = 1.0""")) testdir.makeconftest(""" def pytest_addoption(parser): - parser.addini("custom", "") - """) + parser.addini("custom", "")""") testdir.makepyfile(""" def test_pass(pytestconfig): 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") assert result.ret == 0 - result.stdout.fnmatch_lines([ - "custom_option:2.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" - ]) + 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") - """) + def pytest_addoption(parser): + parser.addini("paths", "my new ini value", type="pathlist")""") testdir.makeini(""" - [pytest] - paths=blah.py - """) + [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" - ]) + 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"]) 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") - - """) + def pytest_addoption(parser): + addini = parser.addini + addini("custom_option_1", "", default="o1") + addini("custom_option_2", "", default="o2") + addini("custom_option_3", "", default=False, type="bool") + addini("custom_option_4", "", default=True, type="bool")""") testdir.makeini(""" - [pytest] - custom_option_1=custom_option_1 - custom_option_2=custom_option_2 - """) + [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" - ]) + 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"])