Problems with MockTestCase in plone.dexterity

In the zope4-plip the test plone.dexterity.tests.test_utils.TestUtils.test_getAdditionalSchemata fails: http://jenkins.plone.org/view/PLIPs/job/plip-zope4/8/testReport/plone.dexterity.tests.test_utils/TestUtils/test_getAdditionalSchemata/

zope.interface has a python2/3-compatability string-class zope.interface._compat._u

Since https://github.com/zopefoundation/zope.interface/commit/79a266200384fa53fb3810ed316a94394166f4e3
zope.interface uses zope.interface.registry._getName is used to get a name for a nameless adapter using component.__component_name__

But: The tests of plone.dexterity use mocker to mock stuff (adapters, behavior etc...). For a mocker-adapter without a name that does not return a string but <mocker.Mock object at xxxxxxx> which raises an error when _compat tries to normalize it. When we force a name the test fails either when it can no longer lookup the adapter or with "Performed fewer times than expected.".

For me all the tests of plone.dexterity based on MockTestCase are totally incomprehensible. Even worse I consider them unmaintainable when a basically simple issue as the one above prevents me from fixing the tests.

Yes, it is better if you rip em out. They cause test isolation problems with plone.app.testing and/or ZopeTestCase.

1 Like

We should try to get rid of this dependency since the package itself is unmaintained as far as I know. Though, I would prefer to rewrite the tests with mock or with integration tests rather than just removing them.

1 Like

fixed in plone.mocktestcase https://github.com/plone/plone.mocktestcase/commit/97dbd21bd1116b76f82d843e663d1bd7fd93d6fc
dirty but works, but hey, whole mocktestcase is ugly.

Thanks for this but I really think it would be better to replace these tests instead of fixing them. I don't think it takes much more time to rewrite them than to maintain them.

Fixing this by replacing mocktestcase is a huge mount of work, at least one full week for a experienced Plone developer not knowing the internals of the old tests, dexterity and whats the rational behind, a bit less for one of the in-depth core devs and much more for a beginner. I doubt this can be done w/o any funding.

I spent an hour or so on it and am about 25% done. Progress so far in the davisagli-remove-mocktestcase branch of plone.dexterity.

I'm not really changing what the tests attempt to do, but am converting it to use mock instead of plone.mocktestcase and mocker. (This is clearly the way to go since mock is included in Python 3 as unittest.mock.)

1 Like

Looks good. That's a smart way to get it done. Anyway, we should get rid of the call counts. They do not really tests anything and they make refactoring a hell. But maybe that's a different topic.

May you finish this?

The PR is ready to merge now: https://github.com/plone/plone.dexterity/pull/62

awesome! and merged!