3

This question is basically the same as Python doctest: skip a test conditionally, except I'm not asking about Python's native doctest module but about Sphinx's doctest extension:

Is there any way to skip doctests "dynamically" depending on some condition, which could e.g. be evaluated in the setup code for the given reST file? The documentation doesn't mention anything of the sort, but maybe someone has a good workaround.

4
  • 2
    This feature might not be that hard to create and contribute in sphinx.ext.doctest. It already includes the pyversion option (e.g. :pyversion: > 3.3), and a conditional skip would work very similarly. Commented Aug 7, 2018 at 5:17
  • 1
    I opened Sphinx issue #5273 and created a patch with this feature for the upcoming Sphinx 1.8 version. Commented Aug 7, 2018 at 9:12
  • 1
    Incidentally, the time is exactly right for this feature. Before the current 1.8 development code base, evaluating conditions in the context set up in the doctest_global_setup configuration option would have been hard, since directives didn't have access to configuration. Commented Aug 7, 2018 at 9:15
  • @akaihola You could post a short snippet on how to use your feature as an answer and I'll mark it as the accepted answer. Commented Sep 30, 2020 at 4:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.