Skip to content

Use pytest-doctestplus instead of classic pytest-doctest - #7289

Merged
mkcor merged 2 commits into
scikit-image:mainfrom
lagru:use-doctestplus
Jan 16, 2024
Merged

mkcor merged 2 commits into
scikit-image:mainfrom
lagru:use-doctestplus

Conversation

@lagru

@lagru lagru commented Jan 11, 2024

Copy link
Copy Markdown
Member

Description

This has the advantage of being able to hide custom test setup from the rendered HTML docstrings and many more perks we might use in the future. E.g. in the past I've wished for access to # doctest: +FLOAT_CMP, # doctest: +IGNORE_WARNINGS or .. testsetup::.

See also https://github.com/scientific-python/pytest-doctestplus.

Checklist

Release note

Summarize the introduced changes in the code block below in one or a few sentences. The
summary will be included in the next release notes automatically:

...

This has the advantage of being able to hide custom test setup from
the rendered HTML docstrings and many more perks we might use in the
future.

doctestplus has its own mechanism of skipping doctests if dependencies
are not required. However, it seems that using `__doctest_skip__` will
not show that tests were skipped, so instead I'm using an approach
based on `.. testsetup` and `pytest.importorskip`.
@lagru lagru added the 🤖 type: Infrastructure CI, packaging, tools and automation label Jan 11, 2024
Comment on lines +82 to +84
.. testsetup::
>>> import pytest; _ = pytest.importorskip('sklearn')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctestplus has its own mechanism of skipping doctests if dependencies are missing. However, it seems that using __doctest_skip__ will not show that tests were skipped and I couldn't get .. doctest-requires:: to work. So instead I'm using an approach based on .. testsetup and pytest.importorskip.

@lagru lagru mentioned this pull request Jan 11, 2024
18 tasks done
as well. It's needed to parse the .. testsetup fixture.
--------
>>> import pytest
>>> _ = pytest.importorskip('sklearn')
.. testsetup::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the explicitness of this!

@soupault soupault left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good addition considering the size and the complexity of our tests codebase.

@mkcor
mkcor merged commit f4c1b34 into scikit-image:main Jan 16, 2024
@stefanv stefanv added this to the 0.23 milestone Jan 16, 2024
@lagru
lagru deleted the use-doctestplus branch January 16, 2024 17:38
@lagru lagru mentioned this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 type: Infrastructure CI, packaging, tools and automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants