[Grok-dev] Re: Minimal setup for testing adapters

Martijn Faassen faassen at startifact.com
Wed Mar 19 15:00:05 EDT 2008


Luciano Ramalho wrote:
> A minimal unittest setup cannot be used to check adapters, and
> previously I've used full-blown functional tests to check whether
> adapters are working in my apps. But I think this is overkill, so can
> anyone point me to a minimal test setup that allows me to test
> adapters?

Use grok.testing.grok() in your test to let it grok the module that 
defines the adapters:

   >>> grok.testing.grok('some.module)

In addition you can also define adapters in your test itself and then 
manually grok them:

   >>> class Foo(grok.Adapter):
   ...   grok.provides(IFoo)
   ...   grok.context(Bar)
   >>> grok.testing.grok_component('Foo', Foo)

Note that I do sometimes still cheat and use 'overkill' ftests myself; 
they tend to run fast enough and often I don't mind getting the whole 
configuration there.



More information about the Grok-dev mailing list