[Zope-dev] Announcement: gocept.zcapatch 1.0 released

Wolfgang Schnerring ws at gocept.com
Tue Dec 6 17:31:09 UTC 2011


* Stephan Richter <stephan.richter at gmail.com> [2011-12-05 09:16]:
> On Monday, December 05, 2011 12:43:35 PM Wolfgang Schnerring wrote:
> > So we decided to solve our most immediate needs (that are not taken
> > care of by plone.testing's stacking solution of the global registry),
> > namely temporarily altering utility/adapter/handler registrations.
> 
> Why did you not just wrap the config in a z3c.basegeistry directive?

I'm afraid I don't understand how that could help in what I'd like to
do. The use case I'm concerned with looks roughly like this:

    def test_client_code_that_uses_IFoo_utility_correctly(self):
        fake_utility = mock.Mock()
        fake_utility.underlying_method.return_value = 'canned response'
        self.zca.patch_utility(fake_utility, IFoo)
        client_code.perform()
        fake_utility.underlying_method.assert_called_with(correct_arguments)

With the additional conditions that
- I'm probably loading configure.zcml in the layer of this test, which
defines real IFoo (and, possibly, IBar) utilities.
- The client code under test might (or might not) use IBar; either way,
I don't care, and certainly don't want to have to mock it, too, for
*this* test.
- Other tests will likewise want the real IFoo implementation.

In other words, I want to replace the utility precisely for this test,
isolated from all other tests, and isolated from the layer setup
below. plone.testing's stacking approach might help, but only as long
as only zope.component.getGlobalSiteManager() is concerned, and as
long as I'm only adding or exchanging stuff (come to think of it, I
should go and check whether I can "remove" things registered in
__bases__ by registering None in the stacked registry...).

As far as I can tell, z3c.baseregistry merely introduces another
registry (with __bases__ set up sensibly), so I don't think that can
help here, or can it?

Wolfgang

-- 
Wolfgang Schnerring · email/jabber: ws at gocept.com · software development
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 219401 0 · fax +49 345 1229889 1
Python, Pyramid, Plone, Zope - consulting, development, hosting, operations
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.zope.org/pipermail/zope-dev/attachments/20111206/8881a864/attachment.sig>


More information about the Zope-Dev mailing list