Skip to content

Make skipping of doctests more visible? #246

Closed

Description

@lagru

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

Activity

  1. lagru commented on Mar 17, 2024

    @lagru
    MemberAuthor

    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.

  2. pllim commented on Mar 17, 2024

    @pllim
    Contributor

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

    Any performance impact?

  3. bsipocz commented on Mar 19, 2024

    @bsipocz
    Member

    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)

  4. lagru commented on Mar 19, 2024

    @lagru
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions