diff --git a/_pytest/config.py b/_pytest/config.py index d97771155a..359cc4bc84 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -1327,10 +1327,14 @@ 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 = str(inifile).endswith('.cfg') + sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest'] + for section in sections: + try: + inicfg = iniconfig[section] + break + except KeyError: + inicfg = None rootdir = get_common_ancestor(dirs) else: ancestor = get_common_ancestor(dirs) diff --git a/changelog/3260.bugfix.rst b/changelog/3260.bugfix.rst new file mode 100644 index 0000000000..eb0ecd3457 --- /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. diff --git a/testing/test_config.py b/testing/test_config.py index f256b512f5..39105f5d68 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -110,6 +110,13 @@ def pytest_addoption(parser): 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]