From 3f7223af443d68c18c90ffc84f58c5f0e9952cb0 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 27 Feb 2018 19:02:49 +0300 Subject: [PATCH 1/6] #3260 Fix pytest section in setup ini file --- _pytest/config.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index d97771155..68d66ee2a 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -1327,10 +1327,17 @@ def determine_setup(inifile, args, warnfunc=None): dirs = get_dirs_from_args(args) if inifile: iniconfig = py.iniconfig.IniConfig(inifile) - try: - inicfg = iniconfig["pytest"] - except KeyError: - inicfg = None + is_cfg_file = '.cfg' in inifile + sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest'] + for section in sections: + try: + inicfg = iniconfig[section] + if is_cfg_file and section == 'pytest' and warnfunc: + from _pytest.deprecated import SETUP_CFG_PYTEST + warnfunc('C1', SETUP_CFG_PYTEST.replace('setup.cfg', inifile)) + break + except KeyError: + inicfg = None rootdir = get_common_ancestor(dirs) else: ancestor = get_common_ancestor(dirs) From eadd15fe4591c4e1c1c949a489cfc53976b5b543 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 27 Feb 2018 19:05:53 +0300 Subject: [PATCH 2/6] #3260 Added changelog file --- changelog/3260.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3260.bugfix diff --git a/changelog/3260.bugfix b/changelog/3260.bugfix new file mode 100644 index 000000000..49dc41c50 --- /dev/null +++ b/changelog/3260.bugfix @@ -0,0 +1 @@ +Fixed ``tool:pytest`` section when setup.cfg passed by option ``-c`` From 409b919fc0cf291b38cabb7eb991b086323e5d1b Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 27 Feb 2018 19:16:45 +0300 Subject: [PATCH 3/6] #3260 Added test --- testing/test_config.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/test_config.py b/testing/test_config.py index f256b512f..39105f5d6 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -110,6 +110,13 @@ class TestConfigCmdlineParsing(object): config = testdir.parseconfig("-c", "custom.cfg") assert config.getini("custom") == "1" + testdir.makefile(".cfg", custom_tool_pytest_section=""" + [tool:pytest] + custom = 1 + """) + config = testdir.parseconfig("-c", "custom_tool_pytest_section.cfg") + assert config.getini("custom") == "1" + def test_absolute_win32_path(self, testdir): temp_cfg_file = testdir.makefile(".cfg", custom=""" [pytest] From 143ac5af99cc56b1868741b095ad7db7eccde73c Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 27 Feb 2018 19:26:35 +0300 Subject: [PATCH 4/6] #3260 Fix config.py for py27 --- _pytest/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 68d66ee2a..c84bbe134 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -1327,14 +1327,15 @@ def determine_setup(inifile, args, warnfunc=None): dirs = get_dirs_from_args(args) if inifile: iniconfig = py.iniconfig.IniConfig(inifile) - is_cfg_file = '.cfg' in inifile + is_cfg_file = str(inifile).endswith('.cfg') + # TODO: [pytest] section in *.cfg files is depricated. Need refactoring. sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest'] for section in sections: try: inicfg = iniconfig[section] if is_cfg_file and section == 'pytest' and warnfunc: from _pytest.deprecated import SETUP_CFG_PYTEST - warnfunc('C1', SETUP_CFG_PYTEST.replace('setup.cfg', inifile)) + warnfunc('C1', SETUP_CFG_PYTEST.replace('setup.cfg', str(inifile))) break except KeyError: inicfg = None From 92219e576bcb8d62e0d75e0bf8d10aad58320dde Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 27 Feb 2018 20:00:46 +0300 Subject: [PATCH 5/6] #3260 Remove deprecation --- _pytest/config.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index c84bbe134..359cc4bc8 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -1328,14 +1328,10 @@ def determine_setup(inifile, args, warnfunc=None): if inifile: iniconfig = py.iniconfig.IniConfig(inifile) is_cfg_file = str(inifile).endswith('.cfg') - # TODO: [pytest] section in *.cfg files is depricated. Need refactoring. sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest'] for section in sections: try: inicfg = iniconfig[section] - if is_cfg_file and section == 'pytest' and warnfunc: - from _pytest.deprecated import SETUP_CFG_PYTEST - warnfunc('C1', SETUP_CFG_PYTEST.replace('setup.cfg', str(inifile))) break except KeyError: inicfg = None From 1fb2457018d6a2171b2721c84cb7271a6c2c0667 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 27 Feb 2018 14:58:27 -0300 Subject: [PATCH 6/6] Adjust CHANGELOG --- changelog/3260.bugfix | 1 - changelog/3260.bugfix.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 changelog/3260.bugfix create mode 100644 changelog/3260.bugfix.rst diff --git a/changelog/3260.bugfix b/changelog/3260.bugfix deleted file mode 100644 index 49dc41c50..000000000 --- a/changelog/3260.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fixed ``tool:pytest`` section when setup.cfg passed by option ``-c`` diff --git a/changelog/3260.bugfix.rst b/changelog/3260.bugfix.rst new file mode 100644 index 000000000..eb0ecd345 --- /dev/null +++ b/changelog/3260.bugfix.rst @@ -0,0 +1 @@ +``[tool:pytest]`` sections in ``*.cfg`` files passed by the ``-c`` option are now properly recognized.