[py-svn] commit/pytest: hpk42: add an xfail-ed test for a potential future "enabled" parameter to setup functions

Bitbucket commits-noreply at bitbucket.org
Tue Sep 25 15:04:38 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/9f3ba4c42151/
changeset:   9f3ba4c42151
user:        hpk42
date:        2012-09-25 15:04:30
summary:     add an xfail-ed test for a potential future "enabled" parameter to setup functions
affected #:  2 files

diff -r d46b4480e6de290d9b965618981f9f186030380f -r 9f3ba4c42151726a208dd4541288817edfb6cf44 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -19,8 +19,10 @@
         return function
 
 class SetupMarker:
-    def __init__(self, scope):
+    def __init__(self, scope, enabled):
         self.scope = scope
+        self.enabled = enabled
+
     def __call__(self, function):
         function._pytestsetup = self
         return function
@@ -36,14 +38,17 @@
     """
     return FactoryMarker(scope, params)
 
-def setup(scope="function"):
+def setup(scope="function", enabled=None):
     """ return a decorator to mark functions as setup functions.
 
     :arg scope: the scope for which the setup function will be active, one
                 of "function", "class", "module", "session".
                 Defaults to "function".
+    :arg enabled: if a callable is specified, enabled(node) will be called
+                and if it returns a false value this setup function
+                will not be called and its funcargs will not be setup.
     """
-    return SetupMarker(scope)
+    return SetupMarker(scope, enabled)
 
 def cached_property(f):
     """returns a cached property that is calculated by function f.


diff -r d46b4480e6de290d9b965618981f9f186030380f -r 9f3ba4c42151726a208dd4541288817edfb6cf44 testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -1898,6 +1898,32 @@
         reprec = testdir.inline_run("-s")
         reprec.assertoutcome(passed=2)
 
+    @pytest.mark.xfail(reason="'enabled' feature not implemented")
+    def test_setup_enabled_functionnode(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+
+            def enabled(parentnode, markers):
+                return "needsdb" in markers
+
+            @pytest.factory(params=[1,2])
+            def db(request):
+                return request.param
+
+            @pytest.setup(enabled=enabled)
+            def createdb(db):
+                pass
+
+            def test_func1(request):
+                assert "db" not in request.funcargnames
+
+            @pytest.mark.needsdb
+            def test_func2(request):
+                assert "db" in request.funcargnames
+        """)
+        reprec = testdir.inline_run("-s")
+        reprec.assertoutcome(passed=2)
+
     def test_callables_nocode(self, testdir):
         """
         a imported mock.call would break setup/factory discovery

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