1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/1bd6fe5fd273/
Changeset:   1bd6fe5fd273
User:        hpk42
Date:        2013-11-21 13:53:04
Summary:     fixed version comparison in pytest.importskip(modname, 
minverstring)
Affected #:  3 files

diff -r 1e714f46ad69bbb150b53ddca1df97c823d650c8 -r 
1bd6fe5fd2731d9e54c1b5e01ebc411c582f6818 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -69,6 +69,8 @@
   One of the positive user-facing effects is that the "request" object 
   can now be used in closures.
 
+- fixed version comparison in pytest.importskip(modname, minverstring)
+
 Changes between 2.4.1 and 2.4.2
 -----------------------------------
 

diff -r 1e714f46ad69bbb150b53ddca1df97c823d650c8 -r 
1bd6fe5fd2731d9e54c1b5e01ebc411c582f6818 _pytest/runner.py
--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -336,7 +336,7 @@
             except Exception:
                 # XXX Only first exception will be seen by user,
                 #     ideally all should be reported.
-                if not exc:
+                if exc is None:
                     exc = sys.exc_info()
         if exc:
             py.builtin._reraise(*exc)
@@ -459,25 +459,25 @@
 
 
 def importorskip(modname, minversion=None):
-    """ return imported module if it has a higher __version__ than the
-    optionally specified 'minversion' - otherwise call py.test.skip()
-    with a message detailing the mismatch.
+    """ return imported module if it has at least "minversion" as its
+    __version__ attribute.  If no minversion is specified the a skip
+    is only triggered if the module can not be imported.
+    Note that version comparison only works with simple version strings
+    like "1.2.3" but not "1.2.3.dev1" or others.
     """
     __tracebackhide__ = True
     compile(modname, '', 'eval') # to catch syntaxerrors
     try:
         __import__(modname)
     except ImportError:
-        py.test.skip("could not import %r" %(modname,))
+        skip("could not import %r" %(modname,))
     mod = sys.modules[modname]
     if minversion is None:
         return mod
     verattr = getattr(mod, '__version__', None)
-    if isinstance(minversion, str):
-        minver = minversion.split(".")
-    else:
-        minver = list(minversion)
-    if verattr is None or verattr.split(".") < minver:
-        py.test.skip("module %r has __version__ %r, required is: %r" %(
-                     modname, verattr, minversion))
+    def intver(verstring):
+        return [int(x) for x in verstring.split(".")]
+    if verattr is None or intver(verattr) < intver(minversion):
+        skip("module %r has __version__ %r, required is: %r" %(
+             modname, verattr, minversion))
     return mod

diff -r 1e714f46ad69bbb150b53ddca1df97c823d650c8 -r 
1bd6fe5fd2731d9e54c1b5e01ebc411c582f6818 testing/test_runner.py
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -469,11 +469,11 @@
         assert path.purebasename == "test_runner"
         pytest.raises(SyntaxError, "py.test.importorskip('x y z')")
         pytest.raises(SyntaxError, "py.test.importorskip('x=y')")
-        path = importorskip("py", minversion=".".join(py.__version__))
+        path = importorskip("py", minversion=py.__version__)
         mod = py.std.types.ModuleType("hello123")
         mod.__version__ = "1.3"
         pytest.raises(pytest.skip.Exception, """
-            py.test.importorskip("hello123", minversion="5.0")
+            py.test.importorskip("hello123", minversion="1.3.1")
         """)
     except pytest.skip.Exception:
         print(py.code.ExceptionInfo())

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

Reply via email to