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.

smheidrich
  • 4,063
  • 1
  • 17
  • 30
  • 2
    This feature might not be that hard to create and contribute in `sphinx.ext.doctest`. It already includes the [pyversion](http://www.sphinx-doc.org/en/master/usage/extensions/doctest.html#directive-doctest) option (e.g. `:pyversion: > 3.3`), and a conditional skip would work very similarly. – akaihola Aug 07 '18 at 05:17
  • 1
    I opened Sphinx issue [#5273](https://github.com/sphinx-doc/sphinx/issues/5273) and created a [patch](https://github.com/akaihola/sphinx/commit/10f01d5539110c2080b69aff90af6ca0d269f0df) with this feature for the upcoming Sphinx 1.8 version. – akaihola Aug 07 '18 at 09: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. – akaihola Aug 07 '18 at 09: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. – smheidrich Sep 30 '20 at 04:22

0 Answers0