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
We've started using doctestplus in scikit-image and I'm happy with it so far. However, my main gripe with it is that (conditional) skipping doctest isn't very visible. E.g. when I use __doctest_requires__ to mark functions then these are just silently not collected and ignored. Instead I would like to figure out if we can still collect these but mark them to be skipped the same way as if I added pytest.importorskip("pywt") to the doctest itself...
I could try looking into this but first I'd like to know if there are any concerns with this approach. And also were I should start..
Playing around with this, I think one approach would be to insert new lines into doctests during collection that cause pytest to skip. E.g.
--- pytest_doctestplus/plugin.py+++ pytest_doctestplus/plugin.py@@ -874,8 +874,14 @@
else:
continue # The pattern does not apply
- if not self.check_required_modules(mods):- return False+ for mod in mods:+ example = doctest.Example(+ source=f"import pytest; pytest.importorskip({mod!r})",+ want="",+ exc_msg=None,+ )+ test.examples.insert(0, example)+
return True
tests = list(filter(test_filter, tests))
Not sure how "hacky" you consider this approach but it seems to address my feature request perfectly.
I agree that counting them into the skipped total would be nice (though big narrative docs file usually count as one, so partial skipping rst files may not be able to work this way)
Activity
lagru commentedon Mar 17, 2024
Playing around with this, I think one approach would be to insert new lines into doctests during collection that cause pytest to skip. E.g.
Not sure how "hacky" you consider this approach but it seems to address my feature request perfectly.
pllim commentedon Mar 17, 2024
I wonder if @nicoddemus & co could advise since we plug into doctest within pytest itself.
Any performance impact?
bsipocz commentedon Mar 19, 2024
I agree that counting them into the skipped total would be nice (though big narrative docs file usually count as one, so partial skipping rst files may not be able to work this way)
lagru commentedon Mar 19, 2024
Right, the suggested patch and our usage in scikit-image are mainly concerned with docstrings right now.