You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
support using a variable (or expression) for conditional skipping, not just a dependency #193
I went through the issue tracker and I think this exact issue has not been discussed yet:
It looks like the current support for conditional skipping is limited to checking for whether a dependency is available.[1]
But some blocks need to be skipped in other situations, e.g. when running with a too-old Python version, or under an alternative Python implementation such as PyPy.
As prior art, sphinx.ext.doctest has a :skipif: option that allows conditionally skipping doctest blocks using an arbitrary Python expression (e.g. :skipif: sys.version_info < (3,). Something like that would be perfect here.
Or if it's easier, perhaps the existing doctest-requires directive could be expanded to accept a variable rather than a dependency name, e.g.
# docs/foo.rst
.. doctest-requires:: cpython
>>> float('nan') is float('nan') # True for PyPy
False
and a conftest.py could define the variable in the doctest_namespace:
Having a conditional feature would be nice, I suppose we just need to converge on whether to have it as an option for the currently existing doctest-requires or add a new skip-if (or preferably calling it doctest-skip?).
Do you have any time to work on a PR for this @jab?
Right, sphinx.ext.doctest is not the same as the standard library's doctest module. It's the former that provides skip-if, not the latter.
Wonderful to hear there's interest in adding support for skip-if here. I believe that would make pytest-doctestplus the only pytest plugin to offer support for this, which would make it the only solution for projects like mine that need this (example). (pytest-sphinx started adding support for this years ago, but the implementation has not been completed yet. See also sphinx-doc/sphinx#1487.)
Would be nice if we can take advantage of sphinx.ext.doctest somehow without reinventing the wheel but I am also not familiar with the code here. Hopefully @bsipocz can come up with something. Thanks! 🤞 🙇♀️
General 👍 to this idea -- will be helpful for people needing to deal with the changes in how units are represented (thanks @pllim for pointing to this!).
Activity
bsipocz commentedon Jan 10, 2023
Having a conditional feature would be nice, I suppose we just need to converge on whether to have it as an option for the currently existing
doctest-requiresor add a newskip-if(or preferably calling itdoctest-skip?).Do you have any time to work on a PR for this @jab?
pllim commentedon Jan 17, 2023
Why is doctestplus not using the built-in skipif from doctest? 🤔
bsipocz commentedon Jan 18, 2023
I don't have access to code atm, but is the sphinx doctest extension the same as the built-in doctest? I would have guessed no.
OTOH, we certainly support a few things from it already so it's worth comparing whether e.g. testsetup works automatically or not.
jab commentedon Jan 18, 2023
Right, sphinx.ext.doctest is not the same as the standard library's doctest module. It's the former that provides
skip-if, not the latter.Wonderful to hear there's interest in adding support for
skip-ifhere. I believe that would make pytest-doctestplus the only pytest plugin to offer support for this, which would make it the only solution for projects like mine that need this (example). (pytest-sphinx started adding support for this years ago, but the implementation has not been completed yet. See also sphinx-doc/sphinx#1487.)I took a quick look at https://github.com/astropy/pytest-doctestplus/blob/main/pytest_doctestplus/sphinx/doctestplus.py with an eye toward contributing this, but couldn't immediately see how to do it, and am not sure when I could find more time for it (recently started a new job, and have a 6-month-old at home:). Would this be pretty straightforward to add though for a core maintainer or a more experienced outside contributor to this project?
Thanks for your consideration!
bsipocz commentedon Jan 18, 2023
I have some offline flight hours later this week to fill with a suitably standalone project, will try to have a look at this then.
pllim commentedon Jan 18, 2023
Would be nice if we can take advantage of
sphinx.ext.doctestsomehow without reinventing the wheel but I am also not familiar with the code here. Hopefully @bsipocz can come up with something. Thanks! 🤞 🙇♀️mhvk commentedon Mar 13, 2023
General 👍 to this idea -- will be helpful for people needing to deal with the changes in how units are represented (thanks @pllim for pointing to this!).