[Pytest-commit] commit/pytest: hpk42: - restore compatibility to old getvalueorskip behaviour

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed May 14 08:12:25 CEST 2014


1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/ba0faffae819/
Changeset:   ba0faffae819
User:        hpk42
Date:        2014-05-14 07:36:31
Summary:     - restore compatibility to old getvalueorskip behaviour
- introduce a better NOTSET representation to improve docs
Affected #:  2 files

diff -r f0446f3f8db3a9e03c0266d0be7e145c8a351f50 -r ba0faffae8191c03a51d71135a76822f454198d7 _pytest/config.py
--- a/_pytest/config.py
+++ b/_pytest/config.py
@@ -560,7 +560,11 @@
     def __repr__(self):
         return "<CmdOptions %r>" %(self.__dict__,)
 
-notset = object()
+class Notset:
+    def __repr__(self):
+        return "<NOTSET>"
+
+notset = Notset()
 FILE_OR_DIR = 'file_or_dir'
 class Config(object):
     """ access to configuration values, pluginmanager and plugin hooks.  """
@@ -798,11 +802,15 @@
         :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 -r f0446f3f8db3a9e03c0266d0be7e145c8a351f50 -r ba0faffae8191c03a51d71135a76822f454198d7 testing/test_config.py
--- a/testing/test_config.py
+++ b/testing/test_config.py
@@ -117,6 +117,15 @@
         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):

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.


More information about the pytest-commit mailing list