Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make skipping of doctests more visible? #246

Open
lagru opened this issue Mar 17, 2024 · 4 comments
Open

Make skipping of doctests more visible? #246

lagru opened this issue Mar 17, 2024 · 4 comments

Comments

@lagru
Copy link
Member

lagru commented Mar 17, 2024

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..

@lagru
Copy link
Member Author

lagru commented 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.

--- 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.

@pllim
Copy link
Contributor

pllim commented Mar 17, 2024

I wonder if @nicoddemus & co could advise since we plug into doctest within pytest itself.

Any performance impact?

@bsipocz
Copy link
Member

bsipocz commented 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
Copy link
Member Author

lagru commented Mar 19, 2024

Right, the suggested patch and our usage in scikit-image are mainly concerned with docstrings right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants