diff --git a/_pytest/config.py b/_pytest/config.py index b738159e2..837da7f21 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -560,7 +560,11 @@ class CmdOptions(object): def __repr__(self): return "" %(self.__dict__,) -notset = object() +class Notset: + def __repr__(self): + return "" + +notset = Notset() FILE_OR_DIR = 'file_or_dir' class Config(object): """ access to configuration values, pluginmanager and plugin hooks. """ @@ -798,11 +802,15 @@ class Config(object): :arg name: name of the option. You may also specify the literal ``--OPT`` option instead of the "dest" option name. :arg default: default value if no option of that name exists. - :arg skip: if True raise pytest.skip if not option exists. + :arg skip: if True raise pytest.skip if option does not exists + or has a None value. """ name = self._opt2dest.get(name, name) try: - return getattr(self.option, name) + val = getattr(self.option, name) + if val is None and skip: + raise AttributeError(name) + return val except AttributeError: if default is not notset: return default diff --git a/testing/test_config.py b/testing/test_config.py index 524d60cac..02c796a87 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -117,6 +117,15 @@ class TestConfigAPI: verbose = config.getvalueorskip("verbose") assert verbose == config.option.verbose + def test_config_getvalueorskip_None(self, testdir): + testdir.makeconftest(""" + def pytest_addoption(parser): + parser.addoption("--hello") + """) + config = testdir.parseconfig() + pytest.raises(pytest.skip.Exception, + "config.getvalueorskip('hello')") + def test_getoption(self, testdir): config = testdir.parseconfig() with pytest.raises(ValueError):