summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--lib/fixtures/_fixtures/monkeypatch.py8
-rw-r--r--lib/fixtures/tests/_fixtures/test_monkeypatch.py15
3 files changed, 28 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 0cc10dc..864f687 100644
--- a/NEWS
+++ b/NEWS
@@ -11,10 +11,15 @@ CHANGES
* ``FakePopen`` now supports being called under a context manager (IE: with).
(Steve Kowalik)
+
* ``FakeProcess`` now supports kill(). (Steve Kowalik)
+
* ``FakeProcess`` wait() now supports arguments added in Python 3.
(Steve Kowalik)
+* ``MonkeyPatch`` now preserves ``staticmethod`` functions.
+ (Dan Kenigsberg)
+
0.3.14
~~~~~~
diff --git a/lib/fixtures/_fixtures/monkeypatch.py b/lib/fixtures/_fixtures/monkeypatch.py
index 42de7ec..858c587 100644
--- a/lib/fixtures/_fixtures/monkeypatch.py
+++ b/lib/fixtures/_fixtures/monkeypatch.py
@@ -17,6 +17,9 @@ __all__ = [
'MonkeyPatch'
]
+import sys
+import types
+
from fixtures import Fixture
@@ -62,6 +65,11 @@ class MonkeyPatch(Fixture):
if old_value is sentinel:
self.addCleanup(self._safe_delete, current, attribute)
else:
+ # Python 2's setattr transforms function into instancemethod
+ if (sys.version_info.major == 2 and
+ isinstance(current, (type, types.ClassType)) and
+ isinstance(old_value, types.FunctionType)):
+ old_value = staticmethod(old_value)
self.addCleanup(setattr, current, attribute, old_value)
def _safe_delete(self, obj, attribute):
diff --git a/lib/fixtures/tests/_fixtures/test_monkeypatch.py b/lib/fixtures/tests/_fixtures/test_monkeypatch.py
index b5977d3..1a84d7f 100644
--- a/lib/fixtures/tests/_fixtures/test_monkeypatch.py
+++ b/lib/fixtures/tests/_fixtures/test_monkeypatch.py
@@ -19,6 +19,11 @@ from fixtures import MonkeyPatch, TestWithFixtures
reference = 23
+class C(object):
+ @staticmethod
+ def foo(): pass
+def bar(): pass
+
class TestMonkeyPatch(testtools.TestCase, TestWithFixtures):
def test_patch_and_restore(self):
@@ -66,3 +71,13 @@ class TestMonkeyPatch(testtools.TestCase, TestWithFixtures):
finally:
fixture.cleanUp()
self.assertFalse('new_attr' in globals())
+
+ def test_patch_staticmethod(self):
+ oldfoo = C.foo
+ fixture = MonkeyPatch(
+ 'fixtures.tests._fixtures.test_monkeypatch.C.foo',
+ bar)
+ with fixture:
+ pass
+ self.assertEqual(oldfoo, C.foo)
+