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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Mar 26 19:05:52 CET 2014


4 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/b79c1f94f7d6/
Changeset:   b79c1f94f7d6
User:        cgilling
Date:        2014-03-03 19:36:59
Summary:     Fix to work properly when @patch is used with new not equal to DEFAULT

also updated test_mock to include this situation
Affected #:  2 files

diff -r 3ba7553c51cb0a85333f73be76aeffb9733450a6 -r b79c1f94f7d65333ce68d5518f369d599e31a60e _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1836,7 +1836,13 @@
     if startindex is None:
         startindex = inspect.ismethod(function) and 1 or 0
     if realfunction != function:
-        startindex += len(getattr(function, "patchings", []))
+        try:
+            from mock import DEFAULT
+            for patching in getattr(function, "patchings", []):
+                if not patching.attribute_name and patching.new is DEFAULT:
+                    startindex += 1
+        except ImportError:
+            startindex += len(getattr(function, "patchings", []))
         function = realfunction
     argnames = inspect.getargs(py.code.getrawcode(function))[0]
     defaults = getattr(function, 'func_defaults',

diff -r 3ba7553c51cb0a85333f73be76aeffb9733450a6 -r b79c1f94f7d65333ce68d5518f369d599e31a60e testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -124,8 +124,11 @@
                 def test_hello(self, abspath):
                     os.path.abspath("hello")
                     abspath.assert_any_call("hello")
+            def mock_basename(path):
+                return "mock_basename"
             @mock.patch("os.path.abspath")
             @mock.patch("os.path.normpath")
+            @mock.patch("os.path.basename",new=mock_basename)
             def test_someting(normpath, abspath, tmpdir):
                 abspath.return_value = "this"
                 os.path.normpath(os.path.abspath("hello"))


https://bitbucket.org/hpk42/pytest/commits/c93d674ac9f9/
Changeset:   c93d674ac9f9
User:        cgilling
Date:        2014-03-26 17:27:33
Summary:     change try/except to sys.module.get and a conditional
Affected #:  1 file

diff -r b79c1f94f7d65333ce68d5518f369d599e31a60e -r c93d674ac9f9b838d200fe1f82cc4602f124fb16 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1836,12 +1836,12 @@
     if startindex is None:
         startindex = inspect.ismethod(function) and 1 or 0
     if realfunction != function:
-        try:
-            from mock import DEFAULT
+        mock_default = sys.modules.get('mock.DEFAULT')
+        if mock_default:
             for patching in getattr(function, "patchings", []):
                 if not patching.attribute_name and patching.new is DEFAULT:
                     startindex += 1
-        except ImportError:
+        else:
             startindex += len(getattr(function, "patchings", []))
         function = realfunction
     argnames = inspect.getargs(py.code.getrawcode(function))[0]


https://bitbucket.org/hpk42/pytest/commits/daae64b3edbd/
Changeset:   daae64b3edbd
User:        cgilling
Date:        2014-03-26 17:36:02
Summary:     use sys.modules.get correctly and reference DEFAULT with respect to it
Affected #:  1 file

diff -r c93d674ac9f9b838d200fe1f82cc4602f124fb16 -r daae64b3edbd8d604112dfd3340b60af6c820db0 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1836,10 +1836,10 @@
     if startindex is None:
         startindex = inspect.ismethod(function) and 1 or 0
     if realfunction != function:
-        mock_default = sys.modules.get('mock.DEFAULT')
-        if mock_default:
+        mock = sys.modules.get('mock')
+        if mock is not None:
             for patching in getattr(function, "patchings", []):
-                if not patching.attribute_name and patching.new is DEFAULT:
+                if not patching.attribute_name and patching.new is mock.DEFAULT:
                     startindex += 1
         else:
             startindex += len(getattr(function, "patchings", []))


https://bitbucket.org/hpk42/pytest/commits/9f5aad82d1cf/
Changeset:   9f5aad82d1cf
User:        hpk42
Date:        2014-03-26 19:05:46
Summary:     Merged in cgilling/pytest (pull request #123)

Fix to work properly when @patch is used with new not equal to DEFAULT
Affected #:  2 files

diff -r 071018d4de31ec8d34b7663e50c4a9c633db12a9 -r 9f5aad82d1cf661b9a5b6ddfeb1ca945b3bd21de _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1841,7 +1841,13 @@
     if startindex is None:
         startindex = inspect.ismethod(function) and 1 or 0
     if realfunction != function:
-        startindex += len(getattr(function, "patchings", []))
+        mock = sys.modules.get('mock')
+        if mock is not None:
+            for patching in getattr(function, "patchings", []):
+                if not patching.attribute_name and patching.new is mock.DEFAULT:
+                    startindex += 1
+        else:
+            startindex += len(getattr(function, "patchings", []))
         function = realfunction
     argnames = inspect.getargs(py.code.getrawcode(function))[0]
     defaults = getattr(function, 'func_defaults',

diff -r 071018d4de31ec8d34b7663e50c4a9c633db12a9 -r 9f5aad82d1cf661b9a5b6ddfeb1ca945b3bd21de testing/python/integration.py
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -124,8 +124,11 @@
                 def test_hello(self, abspath):
                     os.path.abspath("hello")
                     abspath.assert_any_call("hello")
+            def mock_basename(path):
+                return "mock_basename"
             @mock.patch("os.path.abspath")
             @mock.patch("os.path.normpath")
+            @mock.patch("os.path.basename",new=mock_basename)
             def test_someting(normpath, abspath, tmpdir):
                 abspath.return_value = "this"
                 os.path.normpath(os.path.abspath("hello"))

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