1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/76a2baa4837d/
Changeset:   76a2baa4837d
User:        hpk42
Date:        2013-10-11 14:36:54
Summary:     avoid one surprising case of marker malfunction/confusion::

    @pytest.mark.some(lambda arg: ...)
    def test_function():

would not work correctly because pytest assumes @pytest.mark.some
gets a function to be decorated already.  We now at least detect if this
arg is an lambda and thus the example will work.  Thanks Alex Gaynor
for bringing it up.
Affected #:  3 files

diff -r 9931e8b59b66c7dca504db56a1ed87066383c0fe -r 
76a2baa4837dfeacdeaca326b74dd918c0d031d9 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,16 @@
   properly so that the pkg_resources.resource_stream method works properly.
   Fixes issue366.  Thanks for the investigations and full PR to Jason R. 
Coombs.
 
+- avoid one surprising case of marker malfunction/confusion::
+  
+      @pytest.mark.some(lambda arg: ...)
+      def test_function():
+
+  would not work correctly because pytest assumes @pytest.mark.some 
+  gets a function to be decorated already.  We now at least detect if this 
+  arg is an lambda and thus the example will work.  Thanks Alex Gaynor
+  for bringing it up.
+
 Changes between 2.4.1 and 2.4.2
 -----------------------------------
 

diff -r 9931e8b59b66c7dca504db56a1ed87066383c0fe -r 
76a2baa4837dfeacdeaca326b74dd918c0d031d9 _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -182,6 +182,9 @@
         if name not in self._markers:
             raise AttributeError("%r not a registered marker" % (name,))
 
+def istestfunc(func):
+    return hasattr(func, "__call__") and \
+        getattr(func, "__name__", "<lambda>") != "<lambda>"
 
 class MarkDecorator:
     """ A decorator for test functions and test classes.  When applied
@@ -217,8 +220,8 @@
             otherwise add *args/**kwargs in-place to mark information. """
         if args:
             func = args[0]
-            if len(args) == 1 and hasattr(func, '__call__') or \
-               hasattr(func, '__bases__'):
+            if len(args) == 1 and (istestfunc(func) or
+                                   hasattr(func, '__bases__')):
                 if hasattr(func, '__bases__'):
                     if hasattr(func, 'pytestmark'):
                         l = func.pytestmark

diff -r 9931e8b59b66c7dca504db56a1ed87066383c0fe -r 
76a2baa4837dfeacdeaca326b74dd918c0d031d9 testing/test_mark.py
--- a/testing/test_mark.py
+++ b/testing/test_mark.py
@@ -100,6 +100,16 @@
         "*a1some*another marker",
     ])
 
+def test_mark_on_pseudo_function(testdir):
+    testdir.makepyfile("""
+        import pytest
+
+        @pytest.mark.r(lambda x: 0/0)
+        def test_hello():
+            pass
+    """)
+    reprec = testdir.inline_run()
+    reprec.assertoutcome(passed=1)
 
 def test_strict_prohibits_unregistered_markers(testdir):
     testdir.makepyfile("""
@@ -510,3 +520,4 @@
 
         assert_test_is_not_selected("__")
         assert_test_is_not_selected("()")
+

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