Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with doctests using zope.schema vocabulary #120

Open
tflorac opened this issue Dec 26, 2022 · 2 comments
Open

Problem with doctests using zope.schema vocabulary #120

tflorac opened this issue Dec 26, 2022 · 2 comments

Comments

@tflorac
Copy link

tflorac commented Dec 26, 2022

I'm actually building a package using zope.schema, actually in release 6.2.1.
My development and Gitlab CI environments are both built using zc.buildout in virtual environments from the same configuration file.
I have a doctest which is checking for a missing vocabulary, but:

  • when running the test in my own local development environment, the raised exception is a NameError:
    Traceback (most recent call last):
      File "/usr/lib/python3.11/doctest.py", line 1350, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest term.rst[69]>", line 1, in <module>
        terms = term.ChoiceTerms(
      File "/var/local/home/tflorac/Dropbox/src/PyAMS-v2/pyams_form/src/pyams_form/term.py", line 116, in ChoiceTerms
        field = field.bind(context)
      File "/var/local/env/pyams-v2-3.11/lib/python3.11/site-packages/zope/schema/_field.py", line 471, in bind
        vocabulary = clone.vocabulary = clone._resolve_vocabulary(None)
      File "/var/local/env/pyams-v2-3.11/lib/python3.11/site-packages/zope/schema/_field.py", line 453, in _resolve_vocabulary
        vocabulary = vr.get(self.context, self.vocabularyName)
      File "/var/local/env/pyams-v2-3.11/lib/python3.11/site-packages/zope/schema/vocabulary.py", line 474, in get
        return vtype(context)
      File "<doctest widget-select-missing-terms.rst[34]>", line 2, in RatingsVocabulary
    NameError: name 'ratings' is not defined
  • when running the test in a Gitlab CI environment, the raised exception is a MissingVocabularyError:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/doctest.py", line 1337, in __run
        compileflags, 1), test.globs)
      File "<doctest term.rst[69]>", line 2, in <module>
        None, request, None, ratingField2, widget)
      File "/builds/pyams/pyams-form/src/pyams_form/term.py", line 116, in ChoiceTerms
        field = field.bind(context)
      File "/builds/pyams/pyams-form/eggs/zope.schema-6.2.1-py3.7.egg/zope/schema/_field.py", line 471, in bind
        vocabulary = clone.vocabulary = clone._resolve_vocabulary(None)
      File "/builds/pyams/pyams-form/eggs/zope.schema-6.2.1-py3.7.egg/zope/schema/_field.py", line 458, in _resolve_vocabulary
        ).with_field_and_value(self, value)
    zope.schema._field.MissingVocabularyError: Can't validate value without vocabulary named 'Ratings'

What could explain this difference while zope.schema is always in the same version?
The only difference, as far as I can see, is that packages are installed using PIP in my development environment, but installed using eggs in Gitlab CI...

P. S.: previous example displays outputs from Python 3.7 and Python 3.11, but the behavior is the same whatever Python version is used!

@mgedmin
Copy link
Member

mgedmin commented Dec 27, 2022

Ah, vocabularies. My "favourite" Zope 3 gotcha, although I cannot say for sure that this is the same thing I remember.

The vocabulary registry is pluggable. There's a default implementation using in-memory dictionaries, and there's an alternative implementation that uses zope.component's utility registry for IVocabularyFactory utilities IIRC. And there's some zope.something module somewhere that switches the registries as an import-time side effect.

So, what Python modules are imported during test discovery may affect the behavior of the tests.

I'm sorry for not being able to provide more precise details, but maybe the gist of the thing will be helpful in your debugging efforts.

@tflorac
Copy link
Author

tflorac commented Dec 28, 2022

Hi Marius,
Thank you for your kind reply!
I'll try to have an inner look at the vocabulary registry used in my tests!
The first step will probably be to create another development environment using the same tools as those used in Gitlab CI, and to see if I get the same behavior...

Best regards,
Thierry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants