Cleaner implementation of early handling of the '-c' command line switch.
--HG-- branch : explicit-ini-filename
This commit is contained in:
parent
c8264385ea
commit
b7f6a9f3fd
|
@ -685,7 +685,15 @@ class Config(object):
|
|||
pytest_load_initial_conftests.trylast = True
|
||||
|
||||
def _initini(self, args):
|
||||
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
|
||||
parsed_args = self._parser.parse_known_args(args)
|
||||
if parsed_args.inifilename:
|
||||
iniconfig = py.iniconfig.IniConfig(parsed_args.inifilename)
|
||||
if 'pytest' in iniconfig.sections:
|
||||
self.inicfg = iniconfig['pytest']
|
||||
else:
|
||||
self.inicfg = {}
|
||||
else:
|
||||
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
|
||||
self._parser.addini('addopts', 'extra command line options', 'args')
|
||||
self._parser.addini('minversion', 'minimally required pytest version')
|
||||
|
||||
|
@ -833,14 +841,6 @@ def exists(path, ignore=EnvironmentError):
|
|||
return False
|
||||
|
||||
def getcfg(args, inibasenames):
|
||||
if "-c" in args:
|
||||
n = len(args)
|
||||
for i in range(1, n):
|
||||
if args[i - 1] == "-c" and not str(args[i]).startswith("-"):
|
||||
iniconfig = py.iniconfig.IniConfig(args[i])
|
||||
if 'pytest' in iniconfig.sections:
|
||||
return iniconfig['pytest']
|
||||
return {}
|
||||
args = [x for x in args if not str(x).startswith("-")]
|
||||
if not args:
|
||||
args = [py.path.local()]
|
||||
|
|
|
@ -38,8 +38,7 @@ def pytest_addoption(parser):
|
|||
help="exit after first num failures or errors.")
|
||||
group._addoption('--strict', action="store_true",
|
||||
help="run pytest in strict mode, warnings become errors.")
|
||||
# This option is never used as such, see config.getcfg().
|
||||
group._addoption("-c", metavar="file", type=str, dest="_inifilename",
|
||||
group._addoption("-c", metavar="file", type=str, dest="inifilename",
|
||||
help="load configuration from `file` instead of trying to locate one of the implicit configuration files.")
|
||||
|
||||
group = parser.getgroup("collect", "collection")
|
||||
|
|
Loading…
Reference in New Issue