ZopeTestCase is missing ZODB connection isolation

Bug #694986 reported by Wolfgang Schnerring
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zope 2
Won't Fix
Wishlist
Unassigned

Bug Description

Hello,

I've stumbled upon an issue with Testing.ZopeTestCase.sandbox: it sets
everything up so that there only ever is one single ZODB connection
per test, that is shared among all requests, the test code,
everything.

While that's more or less fine for the usual functional tests (using
testbrowser or whatnot), it doesn't work well when you want to go
through HTTP (with Selenium, for example) -- especially not when you
want more than one thread to handle HTTP requests.

I have implemented a patch[1] that fixes this issue which I'm using in
gocept.selenium, passing specific tests of the problematic behaviour[2].

Wolfgang

[1] see
http://zope3.pov.lt/trac/browser/gocept.selenium/trunk/src/gocept/selenium/zope2/__init__.py#L48
inlining here for convenience:

Testing.ZopeTestCase.sandbox.Sandbox:
    def _app(self):
 Zope2.startup()
 stuff = Zope2.bobo_application._stuff
 db = Testing.ZopeTestCase.ZopeLite.sandbox()
 Zope2.bobo_application._stuff = (db,) + stuff[1:]
 app = Zope2.bobo_application()
 app = Testing.ZopeTestCase.utils.makerequest(app)
 Testing.ZopeTestCase.connections.register(app)
        return app

[2] see
http://zope3.pov.lt/trac/browser/gocept.selenium/trunk/src/gocept/selenium/tests/isolation
http://zope3.pov.lt/trac/browser/gocept.selenium/trunk/src/gocept/selenium/zope2/tests/zope212/test_zope212.py

Revision history for this message
Hanno Schlichting (hannosch) wrote :

Is there a reason you are not using plone.testing (http://pypi.python.org/pypi/plone.testing) to get proper ZODB isolation?

plone.testing and it's Plone integration layer plone.app.testing have been written to fix many of the shortcomings in zope.testing's layer approach and provide useful layers and helpers for testing Zope and Plone. Going forward I expect ZopeTestCase and the products based on it like PloneTestCase to go away and be replaced with the newer approach.

Changed in zope2:
importance: Undecided → Wishlist
status: New → Opinion
Revision history for this message
Wolfgang Schnerring (wosc) wrote :

Yes, the reason is: I learned about plone.testing only a few days ago (also in relation to gocept.selenium, funnily enough), but that was *after* I already had undertaken an extensive exploration inside ZopeTestCase to find, let alone try and fix, this issue.

And yes, after filing this bug I was trying to compose a question to zope-dev to the effect of "given my (excellent) impressions of plone.testing, are there scenarios other than backwards-compatibility with existing test suites in which ZopeTestCase is recommended over plone.testing?" but hadn't managed to formulate that in a neutral way yet (i.e. not inadvertently bashing ZopeTestCase).

So I guess this answers my question, thanks Hanno. :-) (feel free to "wontfix" this bug if appropriate)

Where would be a good place to document this? The "Zope2 Developers Guide"? It seems to me that http://docs.zope.org/zope2/zdgbook/TestingAndDebugging.html doesn't really talk about either test infrastructure option right now.

Revision history for this message
Hanno Schlichting (hannosch) wrote :

@Wolfgang: Glad to hear plone.testing looks useful to you :)

Regarding documentation: I'm not aware of any documentation for Zope 2 that explains anything even close to current best-practice development with it. If you feel like updating the ZDG that'd be nice - probably ripping out large parts of outdated text would be a good start here ;)

Changed in zope2:
status: Opinion → Won't Fix
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.