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

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

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

lagru
Copy link
Member

@lagru lagru commented Jan 11, 2024

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
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
as well. It's needed to parse the .. testsetup fixture.
@@ -79,8 +79,9 @@ def learn_gmm(descriptors, *, n_modes=32, gm_args=None):

Examples
--------
>>> import pytest
>>> _ = pytest.importorskip('sklearn')
.. testsetup::
Copy link
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!

Copy link
Member

@soupault soupault left a comment

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
22 checks passed
@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.

None yet

4 participants