twmr / pytest-sphinx

sphinx doctest plugin for pytest
BSD 3-Clause "New" or "Revised" License
29 stars 6 forks source link

Support doctest_global_setup #23

Open twmr opened 4 years ago

twmr commented 4 years ago

The doctest plugin in sphinx support specifying a code block in conf.py that is called at setup time

doctest_global_setup = '''
try:
    import pandas as pd
except ImportError:
    pd = None
'''

Support for specifying this code block somewhere should be added.

It can't be added to pytest.ini, because AFAIK it (or ini files in general) doesn't have support for multiline values. So probably it needs to be set in conftest.py. If anyone know how this can be done - please comment.

twmr commented 4 years ago

This is already supported by pytest, see https://docs.pytest.org/en/latest/doctest.html#doctest-namespace-fixture

twmr commented 4 years ago

I created a ticket, where I asked about implementation details of this feature in https://github.com/pytest-dev/pytest/issues/7140