Utility not found when running bin / test in plone 5

In plone 5, I create an interface named IFindMathModeTexInText

and register a global utility with five.grok

like this:

class FindMathModeTexInText (grok.GlobalUtility):
    implements (IFindMathModeTexInText)
    def process(self, text):
        equation_indices, all_indices = find_equation(text)
        return create_list_of_text_nodes(text, equation_indices, all_indices)

      

I named IFindMathModeTexInText

in another module using zope.component.getUtility

as follows:

result = getUtility(IFindMathModeTexInText).process(new_el_text)

      

I have no problem on startup bin/instance fg

However, when I run bin/test

, I got the following error:

in getUtility
    raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass nti.content.util.common_interfaces.IFindMathModeTexInText>, '')

      

I understand that if the utility is not found, a ComponentLookupError will be generated. Why does this error occur at startup bin.test

, and when I run the bin/instance fg

utility is found.

ps: the complete trace is like this:

Error in test test_html_header (nti.content.tools.tests.test_html_to_latex.TestHTMLToLatex)
Traceback (most recent call last):
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/buildout-cache/eggs/unittest2-0.5.1-py2.7.egg/unittest2/case.py", line 340, in run
    testMethod()
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/tests/test_html_to_latex.py", line 31, in test_html_header
    node = RichText.process(script, reading_type = True)
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/rich_text_adapter.py", line 21, in process
    me.add_child(Run.process(element,[],reading_type))
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 25, in process
    me = check_child(me, element, reading_type)
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 322, in check_child
    me.add_child(_process_h1_elements(child,reading_type))
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 393, in _process_h1_elements
    return Paragraph.process(element, ['Heading1'], reading_type)
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 39, in process
    me = check_element_text(me, element)
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 287, in check_element_text
    list_of_child_nodes = getUtility(IFindMathModeTexInText).process(new_el_text)
  File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/buildout-cache/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 169, in getUtility
    raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass nti.content.util.common_interfaces.IFindMathModeTexInText>, '')

      

thank

+3


source to share


1 answer


I solved the problem by specifying the unit-test layer as described in the plone.app.testing documentation .



+2


source







All Articles