def getcfg(args, config=None):
from _pytest.deprecated import CFG_PYTEST_SECTION<EOL>inibasenames = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>args = [x for x in args if not str(x).startswith("<STR_LIT:->")]<EOL>if not args:<EOL><INDENT>args = [py.path.local()]<EOL><DEDENT>for arg in args:<EOL><INDENT>arg = py.path.local(arg)<EOL>for base in arg.parts(reverse=True):<EOL><INDENT>for inibasename in inibasenames:<EOL><INDENT>p = base.join(inibasename)<EOL>if exists(p):<EOL><INDENT>iniconfig = py.iniconfig.IniConfig(p)<EOL>if (<EOL>inibasename == "<STR_LIT>"<EOL>and "<STR_LIT>" in iniconfig.sections<EOL>):<EOL><INDENT>return base, p, iniconfig["<STR_LIT>"]<EOL><DEDENT>elif "<STR_LIT>" in iniconfig.sections:<EOL><INDENT>if inibasename == "<STR_LIT>" and config is not None:<EOL><INDENT>fail(<EOL>CFG_PYTEST_SECTION.format(filename=inibasename),<EOL>pytrace=False,<EOL>)<EOL><DEDENT>return base, p, iniconfig["<STR_LIT>"]<EOL><DEDENT>elif inibasename == "<STR_LIT>":<EOL><INDENT>return base, p, {}<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return None, None, None<EOL>
Search the list of arguments for a valid ini-file for pytest,
and return a tuple of (rootdir, inifile, cfg-dict).

note: config is optional and used only to issue warnings explicitly (#2891).