1 new commit in pytest: https://bitbucket.org/hpk42/pytest/commits/b2dc874930b7/ Changeset: b2dc874930b7 User: hpk42 Date: 2014-06-29 12:08:29 Summary: 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. Affected #: 3 files diff -r f4bdaf606ad155ba3b2ed20d19f914001d4f1806 -r b2dc874930b733c81582cb7aaecda71939dd4686 _pytest/config.py --- a/_pytest/config.py +++ b/_pytest/config.py @@ -685,7 +685,15 @@ 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') diff -r f4bdaf606ad155ba3b2ed20d19f914001d4f1806 -r b2dc874930b733c81582cb7aaecda71939dd4686 _pytest/main.py --- a/_pytest/main.py +++ b/_pytest/main.py @@ -38,6 +38,8 @@ help="exit after first num failures or errors.") group._addoption('--strict', action="store_true", 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.addoption('--collectonly', '--collect-only', action="store_true", diff -r f4bdaf606ad155ba3b2ed20d19f914001d4f1806 -r b2dc874930b733c81582cb7aaecda71939dd4686 testing/test_config.py --- a/testing/test_config.py +++ b/testing/test_config.py @@ -79,6 +79,21 @@ config = testdir.parseconfig() 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: def test_config_trace(self, testdir): Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit