[Pytest-commit] commit/pytest: 6 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Apr 10 22:38:57 CEST 2014


6 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/8690ae5a5508/
Changeset:   8690ae5a5508
Branch:      nose_test_attr
User:        hpk42
Date:        2014-04-10 12:46:27
Summary:     support nose-style ``__test__`` attribute on modules, classes and
functions, including unittest-style Classes.  If set to True, the
test will not be collected.
Affected #:  5 files

diff -r 7a7fe696891309a4e2d9b03001972c6362ffd0ff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -64,6 +64,10 @@
 - fix issue443: fix skip examples to use proper comparison.  Thanks Alex
   Groenholm.
 
+- support nose-style ``__test__`` attribute on modules, classes and
+  functions, including unittest-style Classes.  If set to True, the 
+  test will not be collected.  
+
 
 2.5.2
 -----------------------------------

diff -r 7a7fe696891309a4e2d9b03001972c6362ffd0ff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -314,6 +314,9 @@
                 return True
 
     def collect(self):
+        if not getattr(self.obj, "__test__", True):
+            return []
+
         # NB. we avoid random getattrs and peek in the __dict__ instead
         # (XXX originally introduced from a PyPy need, still true?)
         dicts = [getattr(self.obj, '__dict__', {})]

diff -r 7a7fe696891309a4e2d9b03001972c6362ffd0ff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 _pytest/unittest.py
--- a/_pytest/unittest.py
+++ b/_pytest/unittest.py
@@ -41,10 +41,12 @@
         super(UnitTestCase, self).setup()
 
     def collect(self):
+        cls = self.obj
+        if not getattr(cls, "__test__", True):
+            return
         self.session._fixturemanager.parsefactories(self, unittest=True)
         loader = py.std.unittest.TestLoader()
         module = self.getparent(pytest.Module).obj
-        cls = self.obj
         foundsomething = False
         for name in loader.getTestCaseNames(self.obj):
             x = getattr(self.obj, name)

diff -r 7a7fe696891309a4e2d9b03001972c6362ffd0ff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 doc/en/nose.txt
--- a/doc/en/nose.txt
+++ b/doc/en/nose.txt
@@ -25,6 +25,7 @@
 * SkipTest exceptions and markers
 * setup/teardown decorators
 * yield-based tests and their setup
+* ``__test__`` attribute on modules/classes/functions
 * general usage of nose utilities
 
 Unsupported idioms / known issues

diff -r 7a7fe696891309a4e2d9b03001972c6362ffd0ff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -164,20 +164,21 @@
         names = [x.nodeid.split("::")[-1] for x in calls]
         assert names == ["test_one", "test_two", "test_three"]
 
-    def test_mock_double_patch_issue473(self, testdir):
+    def test_mock_and_mark_issue473(self, testdir):
+        pytest.importorskip("mock", "1.0.1")
         testdir.makepyfile("""
             from mock import patch
             from pytest import mark
 
             @patch('os.getcwd')
             @patch('os.path')
-            @mark.slow
+            #@mark.slow
             class TestSimple:
                 def test_simple_thing(self, mock_path, mock_getcwd):
                     pass
         """)
-        res = testdir.inline_run()
-        res.assertoutcome(passed=1)
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=1)
 
 
 class TestReRunTests:
@@ -214,3 +215,49 @@
 def test_pytestconfig_is_session_scoped():
     from _pytest.python import pytestconfig
     assert pytestconfig._pytestfixturefunction.scope == "session"
+
+
+class TestNoselikeTestAttribute:
+    def test_module(self, testdir):
+        testdir.makepyfile("""
+            __test__ = False
+            def test_hello():
+                pass
+        """)
+        reprec = testdir.inline_run()
+        calls = reprec.getreports("pytest_runtest_logreport")
+        assert not calls
+        
+    def test_class_and_method(self, testdir):
+        testdir.makepyfile("""
+            __test__ = True
+            def test_func():
+                pass
+            test_hello.__test__ = False
+
+            class TestSome:
+                __test__ = False
+                def test_method(self):
+                    pass
+        """)
+        reprec = testdir.inline_run()
+        calls = reprec.getreports("pytest_runtest_logreport")
+        assert not calls
+
+    def test_unittest_class(self, testdir):
+        testdir.makepyfile("""
+            import unittest
+            class TC(unittest.TestCase):
+                def test_1(self):
+                    pass
+            class TC2(unittest.TestCase):
+                __test__ = False
+                def test_2(self):
+                    pass
+        """)
+        reprec = testdir.inline_run()
+        call = reprec.getcalls("pytest_collection_modifyitems")[0]
+        assert len(call.items) == 1
+        assert call.items[0].cls.__name__ == "TC"
+        
+


https://bitbucket.org/hpk42/pytest/commits/588d2bf14ebf/
Changeset:   588d2bf14ebf
Branch:      nose_test_attr
User:        hpk42
Date:        2014-04-10 12:53:33
Summary:     merge default
Affected #:  1 file

diff -r 8690ae5a550883558b7548fe1ffbaadb64f2e948 -r 588d2bf14ebf93f83af2be5e64d7dd3ac45722d2 doc/en/capture.txt
--- a/doc/en/capture.txt
+++ b/doc/en/capture.txt
@@ -84,11 +84,9 @@
 Accessing captured output from a test function
 ---------------------------------------------------
 
-The :ref:`funcarg mechanism` allows test function a very easy
-way to access the captured output by simply using the names
-``capsys`` or ``capfd`` in the test function signature.  Here
-is an example test function that performs some output related
-checks::
+The ``capsys`` and ``capfd`` fixtures allow to access stdout/stderr
+output created during test execution.  Here is an example test function
+that performs some output related checks::
 
     def test_myoutput(capsys): # or use "capfd" for fd-level
         print ("hello")
@@ -108,8 +106,10 @@
 output streams and also interacts well with pytest's
 own per-test capturing.
 
-If you want to capture on ``fd`` level you can use
+If you want to capture on filedescriptor level you can use
 the ``capfd`` function argument which offers the exact
-same interface.
+same interface but allows to also capture output from
+libraries or subprocesses that directly write to operating
+system level output streams (FD1 and FD2).
 
 .. include:: links.inc


https://bitbucket.org/hpk42/pytest/commits/b397dcb8966b/
Changeset:   b397dcb8966b
Branch:      nose_test_attr
User:        hpk42
Date:        2014-04-10 12:56:14
Summary:     fix typo in changelog
Affected #:  1 file

diff -r 588d2bf14ebf93f83af2be5e64d7dd3ac45722d2 -r b397dcb8966ba997ad72e007d3c8d497d5e7ec4a CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -65,7 +65,7 @@
   Groenholm.
 
 - support nose-style ``__test__`` attribute on modules, classes and
-  functions, including unittest-style Classes.  If set to True, the 
+  functions, including unittest-style Classes.  If set to False, the 
   test will not be collected.  
 
 


https://bitbucket.org/hpk42/pytest/commits/13983484d958/
Changeset:   13983484d958
Branch:      nose_test_attr
User:        hpk42
Date:        2014-04-10 12:58:10
Summary:     fix wrong merge
Affected #:  1 file

diff -r b397dcb8966ba997ad72e007d3c8d497d5e7ec4a -r 13983484d95880627faff1f7b9ff518c2d552f0a testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -164,7 +164,7 @@
         names = [x.nodeid.split("::")[-1] for x in calls]
         assert names == ["test_one", "test_two", "test_three"]
 
-    def test_mock_and_mark_issue473(self, testdir):
+    def test_mock_double_patch_issue473(self, testdir):
         pytest.importorskip("mock", "1.0.1")
         testdir.makepyfile("""
             from mock import patch
@@ -172,7 +172,7 @@
 
             @patch('os.getcwd')
             @patch('os.path')
-            #@mark.slow
+            @mark.slow
             class TestSimple:
                 def test_simple_thing(self, mock_path, mock_getcwd):
                     pass


https://bitbucket.org/hpk42/pytest/commits/4535cc997cfb/
Changeset:   4535cc997cfb
Branch:      nose_test_attr
User:        hpk42
Date:        2014-04-10 13:37:39
Summary:     fix tests to properly fail on failed collectiosn (which was hiding an error)
and also implement __test__=False for test functions properly.
Affected #:  2 files

diff -r 13983484d95880627faff1f7b9ff518c2d552f0a -r 4535cc997cfb8d82327f5d17ad1dc855ee7df01d _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -229,10 +229,11 @@
                 "cannot collect %r because it is not a function."
                 % name, )
             return
-        if is_generator(obj):
-            return Generator(name, parent=collector)
-        else:
-            return list(collector._genfunctions(name, obj))
+        if getattr(obj, "__test__", True):
+            if is_generator(obj):
+                return Generator(name, parent=collector)
+            else:
+                return list(collector._genfunctions(name, obj))
 
 def is_generator(func):
     try:

diff -r 13983484d95880627faff1f7b9ff518c2d552f0a -r 4535cc997cfb8d82327f5d17ad1dc855ee7df01d testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -225,6 +225,7 @@
                 pass
         """)
         reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
         calls = reprec.getreports("pytest_runtest_logreport")
         assert not calls
         
@@ -233,7 +234,7 @@
             __test__ = True
             def test_func():
                 pass
-            test_hello.__test__ = False
+            test_func.__test__ = False
 
             class TestSome:
                 __test__ = False
@@ -241,6 +242,7 @@
                     pass
         """)
         reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
         calls = reprec.getreports("pytest_runtest_logreport")
         assert not calls
 
@@ -256,6 +258,7 @@
                     pass
         """)
         reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
         call = reprec.getcalls("pytest_collection_modifyitems")[0]
         assert len(call.items) == 1
         assert call.items[0].cls.__name__ == "TC"


https://bitbucket.org/hpk42/pytest/commits/912a8874de47/
Changeset:   912a8874de47
User:        bubenkoff
Date:        2014-04-10 22:38:53
Summary:     Merged in hpk42/pytest-hpk/nose_test_attr (pull request #154)

support nose-style __test__ attribute to disable collection of test modules/classes/functions
Affected #:  5 files

diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -64,6 +64,10 @@
 - fix issue443: fix skip examples to use proper comparison.  Thanks Alex
   Groenholm.
 
+- support nose-style ``__test__`` attribute on modules, classes and
+  functions, including unittest-style Classes.  If set to False, the 
+  test will not be collected.  
+
 
 2.5.2
 -----------------------------------

diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -229,10 +229,11 @@
                 "cannot collect %r because it is not a function."
                 % name, )
             return
-        if is_generator(obj):
-            return Generator(name, parent=collector)
-        else:
-            return list(collector._genfunctions(name, obj))
+        if getattr(obj, "__test__", True):
+            if is_generator(obj):
+                return Generator(name, parent=collector)
+            else:
+                return list(collector._genfunctions(name, obj))
 
 def is_generator(func):
     try:
@@ -314,6 +315,9 @@
                 return True
 
     def collect(self):
+        if not getattr(self.obj, "__test__", True):
+            return []
+
         # NB. we avoid random getattrs and peek in the __dict__ instead
         # (XXX originally introduced from a PyPy need, still true?)
         dicts = [getattr(self.obj, '__dict__', {})]

diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 _pytest/unittest.py
--- a/_pytest/unittest.py
+++ b/_pytest/unittest.py
@@ -41,10 +41,12 @@
         super(UnitTestCase, self).setup()
 
     def collect(self):
+        cls = self.obj
+        if not getattr(cls, "__test__", True):
+            return
         self.session._fixturemanager.parsefactories(self, unittest=True)
         loader = py.std.unittest.TestLoader()
         module = self.getparent(pytest.Module).obj
-        cls = self.obj
         foundsomething = False
         for name in loader.getTestCaseNames(self.obj):
             x = getattr(self.obj, name)

diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 doc/en/nose.txt
--- a/doc/en/nose.txt
+++ b/doc/en/nose.txt
@@ -25,6 +25,7 @@
 * SkipTest exceptions and markers
 * setup/teardown decorators
 * yield-based tests and their setup
+* ``__test__`` attribute on modules/classes/functions
 * general usage of nose utilities
 
 Unsupported idioms / known issues

diff -r 7b32e3807b231ba322b86223668d805bdacca464 -r 912a8874de477546929a62539680be3e2322e042 testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -165,6 +165,7 @@
         assert names == ["test_one", "test_two", "test_three"]
 
     def test_mock_double_patch_issue473(self, testdir):
+        pytest.importorskip("mock", "1.0.1")
         testdir.makepyfile("""
             from mock import patch
             from pytest import mark
@@ -176,8 +177,8 @@
                 def test_simple_thing(self, mock_path, mock_getcwd):
                     pass
         """)
-        res = testdir.inline_run()
-        res.assertoutcome(passed=1)
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=1)
 
 
 class TestReRunTests:
@@ -214,3 +215,52 @@
 def test_pytestconfig_is_session_scoped():
     from _pytest.python import pytestconfig
     assert pytestconfig._pytestfixturefunction.scope == "session"
+
+
+class TestNoselikeTestAttribute:
+    def test_module(self, testdir):
+        testdir.makepyfile("""
+            __test__ = False
+            def test_hello():
+                pass
+        """)
+        reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
+        calls = reprec.getreports("pytest_runtest_logreport")
+        assert not calls
+        
+    def test_class_and_method(self, testdir):
+        testdir.makepyfile("""
+            __test__ = True
+            def test_func():
+                pass
+            test_func.__test__ = False
+
+            class TestSome:
+                __test__ = False
+                def test_method(self):
+                    pass
+        """)
+        reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
+        calls = reprec.getreports("pytest_runtest_logreport")
+        assert not calls
+
+    def test_unittest_class(self, testdir):
+        testdir.makepyfile("""
+            import unittest
+            class TC(unittest.TestCase):
+                def test_1(self):
+                    pass
+            class TC2(unittest.TestCase):
+                __test__ = False
+                def test_2(self):
+                    pass
+        """)
+        reprec = testdir.inline_run()
+        assert not reprec.getfailedcollections()
+        call = reprec.getcalls("pytest_collection_modifyitems")[0]
+        assert len(call.items) == 1
+        assert call.items[0].cls.__name__ == "TC"
+        
+

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