Fixtures 2.0 is overly strict on monkeypatch requirements

Bug #1567618 reported by Andrew Laski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Fixtures
Fix Released
Undecided
Andrew Laski

Bug Description

Fixtures 2.0 added some better handling of staticmethods in MonkeyPatch, but unintentionally caused a constraint that bound methods of a class be patched with similarly bound methods of that class. This is due to checking the wrong attribute for staticness when doing the patching. As a result workarounds like the following are required:

diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py
index 58ef19e..f72e4e6 100644
--- a/nova/tests/fixtures.py
+++ b/nova/tests/fixtures.py
@@ -584,14 +584,19 @@ class StableObjectJsonFixture(fixtures.Fixture):
     def setUp(self):
         super(StableObjectJsonFixture, self).setUp()

- def _doit(obj, *args, **kwargs):
+ def _obj_to_prim_sorter(obj, *args, **kwargs):
             result = self._original_otp(obj, *args, **kwargs)
             if 'nova_object.changes' in result:
                 result['nova_object.changes'].sort()
             return result

+ # NOTE(alaski): This makes _obj_to_prim_sorter into an instancemethod
+ # so that its signature matches the method it's patching
+ obj_base.NovaObject._obj_to_prim_sorter = _obj_to_prim_sorter
+
         self.useFixture(fixtures.MonkeyPatch(
- 'nova.objects.base.NovaObject.obj_to_primitive', _doit))
+ 'nova.objects.base.NovaObject.obj_to_primitive',
+ obj_base.NovaObject._obj_to_prim_sorter))

 class EngineFacadeFixture(fixtures.Fixture):

I don't think it's desirable that the requirements be that strict.

Revision history for this message
Andrew Laski (alaski) wrote :
Changed in python-fixtures:
assignee: nobody → Andrew Laski (alaski)
status: New → In Progress
Revision history for this message
Robert Collins (lifeless) wrote :

We're discussing on the pull request, but trivial examples still work for me - so ECONFUSED.

Revision history for this message
Robert Collins (lifeless) wrote :

Fixed in 3.0.0.

Changed in python-fixtures:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.