Merged in c_henz/pytest/explicit-ini-filename (pull request #175)
Implement the "-c" command line switch that allows to explicitly specifiy the config file to load.
This commit is contained in:
commit
76d5c9e4f4
|
@ -685,7 +685,15 @@ class Config(object):
|
||||||
pytest_load_initial_conftests.trylast = True
|
pytest_load_initial_conftests.trylast = True
|
||||||
|
|
||||||
def _initini(self, args):
|
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('addopts', 'extra command line options', 'args')
|
||||||
self._parser.addini('minversion', 'minimally required pytest version')
|
self._parser.addini('minversion', 'minimally required pytest version')
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ def pytest_addoption(parser):
|
||||||
help="exit after first num failures or errors.")
|
help="exit after first num failures or errors.")
|
||||||
group._addoption('--strict', action="store_true",
|
group._addoption('--strict', action="store_true",
|
||||||
help="run pytest in strict mode, warnings become errors.")
|
help="run pytest in strict mode, warnings become errors.")
|
||||||
|
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")
|
group = parser.getgroup("collect", "collection")
|
||||||
group.addoption('--collectonly', '--collect-only', action="store_true",
|
group.addoption('--collectonly', '--collect-only', action="store_true",
|
||||||
|
|
|
@ -79,6 +79,21 @@ class TestConfigCmdlineParsing:
|
||||||
config = testdir.parseconfig()
|
config = testdir.parseconfig()
|
||||||
pytest.raises(AssertionError, lambda: config.parse([]))
|
pytest.raises(AssertionError, lambda: config.parse([]))
|
||||||
|
|
||||||
|
def test_explicitly_specified_config_file_is_loaded(self, testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addini("custom", "")
|
||||||
|
""")
|
||||||
|
testdir.makeini("""
|
||||||
|
[pytest]
|
||||||
|
custom = 0
|
||||||
|
""")
|
||||||
|
testdir.makefile(".cfg", custom = """
|
||||||
|
[pytest]
|
||||||
|
custom = 1
|
||||||
|
""")
|
||||||
|
config = testdir.parseconfig("-c", "custom.cfg")
|
||||||
|
assert config.getini("custom") == "1"
|
||||||
|
|
||||||
class TestConfigAPI:
|
class TestConfigAPI:
|
||||||
def test_config_trace(self, testdir):
|
def test_config_trace(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue